Move all files into subfolders based on their Modified date

Discuss and share scripts and script files...
Post Reply
jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Move all files into subfolders based on their Modified date

Post by jacky »

Couple of scripts to do the same thing : move all files in current folders to subfolders based on their Modified date.

I wrote them a while back when I needed it, and kinda forgot about them. I just thought of it again as something like that was asked by kartal, so there you go.

Please note that :
1. you need to switch Recursion Checker off, because there's a loop involved
2. it will move all files in the current folder, if you want something to work only on some/selected files, you'll have to adjust the script obviously (could be done with the help of Looping Through Selected Items I guess, though that one might not be fully compatible with the latest syntax changes!)

Why two scripts? Okay, first one is a very basic thing, just do the work :

Code: Select all

"Move all files into subfolders based on their Modified date"
	// Required config
	setting "HideFoldersInList", 1;
	// focus list (matters for moveto)
	focus l;
	// go up on List
	sel 1,1;
	// start the loop if there's a file to move...
	regexreplace $next, <curitem>, "^$", "_done";
	regexreplace $next, $next, "^((?!_done).)*$", "_loop";
	sub $next;
"_loop"
	// move current item
	moveto "<curpath>\<datem yyyy-mm>\";
	// go up on List
	sel 1,1;
	// continue loop if there's a file to move...
	regexreplace $next, <curitem>, "^$", "_done";
	regexreplace $next, $next, "^((?!_done).)*$", "_loop";
	sub $next;
"_done"
	// done
	status "Finished!"
It works fine, but it bugged me that I got asked whenever moving files to a new folder, so this one will take care of that and do everything on its own (that is: making sure the folder exists, and if not create it first)

Code: Select all

"Move all files into subfolders based on their Modified date - v2"
	// focus list (matters for moveto)
	focus l;
	// Select first file on List
	sel 1,1;
	// start the loop if there's a file to move...
	regexreplace $next, <curitem>, "^$", "_Done";
	regexreplace $next, $next, "^((?!_Done).)*$", "_Loop";
	sub $next;
"_Loop"
	// our file
	set $file, <curitem>;
	set $folder, <datem yyyy-mm>;
	// Show folders
	setting "HideFoldersInList", 0;
	// Select All Files
	sel f;
	// Invert Selection
	sel i;
	// Copy Name(s)
	#102;
	set $all_folders, ":<clipboard>:";
	// Hide folders
	setting "HideFoldersInList", 1;
	// Select first file on List
	sel 1,1;
	// Make sure destination folder exists
	replace $all_folders, $all_folders, <crlf>, ":";
	strpos $pos, $all_folders, ":$folder:";
	// If not an existing folder, create it
	regexreplace $next, $pos, "^-1$", "new ""$folder"", dir;";
	regexreplace $next, $next, "^((?!new ""$folder"", dir;).)*$", "incr $void;";
	load $next,,s;
	// move current item
	moveto "<curpath>\$folder\", $file;
	// Hide folders
	setting "HideFoldersInList", 1;
	// Select first file on List
	sel 1,1;
	// continue loop if there's a file to move...
	regexreplace $next, <curitem>, "^$", "_Done";
	regexreplace $next, $next, "^((?!_Done).)*$", "_Loop";
	sub $next;
"_Done"
	// done
	status "Finished!"
"_nothing"
Both do the same thing, and should work fine. Hopefully this can be helpful to some!
Proud XYplorer Fanatic

kartal
Posts: 208
Joined: 14 Aug 2008 18:06

Re: Move all files into subfolders based on their Modified date

Post by kartal »

Very nice. Could there be a version that can also create based on creation date?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Move all files into subfolders based on their Modified date

Post by jacky »

Sure, just replace <datem yyyy-mm> by <datec yyyy-mm> ;)
Proud XYplorer Fanatic

kartal
Posts: 208
Joined: 14 Aug 2008 18:06

Re: Move all files into subfolders based on their Modified date

Post by kartal »

For some reason I am getting alot of errors. Operations are done successfully but I get alot of error below.
Attachments
XYplorer_Yakala_09-02-2008_15-14-29.png
XYplorer_Yakala_09-02-2008_15-14-29.png (4.59 KiB) Viewed 3191 times
XYplorer_Yakala_09-02-2008_15-12-17.png
XYplorer_Yakala_09-02-2008_15-12-17.png (5.42 KiB) Viewed 3194 times

admin
Site Admin
Posts: 60602
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Move all files into subfolders based on their Modified date

Post by admin »

kartal wrote:For some reason I am getting alot of errors. Operations are done successfully but I get alot of error below.
Are you using the latest BETA version? You should, because scripting has changed a bit since 7.50.0000.

kartal
Posts: 208
Joined: 14 Aug 2008 18:06

Re: Move all files into subfolders based on their Modified date

Post by kartal »

Yes I am using the latest beta. Would you mind trying his scripts?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Move all files into subfolders based on their Modified date

Post by jacky »

admin wrote:
kartal wrote:For some reason I am getting alot of errors. Operations are done successfully but I get alot of error below.
Are you using the latest BETA version? You should, because scripting has changed a bit since 7.50.0000.
Yes it has, but those were written prior to 7.50 and I didn't had to change them, so it shouldn't be a problem anyways. For the record I did try them both with 7.50.0010 and they worked fine.

On which files does it fail? Maybe the files are opened/locked and thus cannot be moved...
Proud XYplorer Fanatic

kartal
Posts: 208
Joined: 14 Aug 2008 18:06

Re: Move all files into subfolders based on their Modified date

Post by kartal »

I do not understand then. I am using the latest beta as well. No locked files nothing should be givin me the error. I added these scripts as user-run script

It works, creates the directories but I am getting errors(move to failed one).

I am under 64bit xp.

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Re: Move all files into subfolders based on their Modified date

Post by lukescammell »

Code: Select all

Error 	28 (0000001C)
Desc	Out of stack space
Dll	0
Proc	script_Process

Source	XYplorer
XY ver	7.50.0009
OS	Vista (Service Pack 1)
Date	03/09/2008 01:07:16
I'm getting that :(
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Move all files into subfolders based on their Modified date

Post by jacky »

kartal wrote:It works, creates the directories but I am getting errors(move to failed one).
Okay, yeah, got it. I was able to get those annoying error messages as well, and BTW when I did I also had an empty folder created, "1899-12", though I'm not sure exactly why.

Apparently XY got confused at times with which item was the current one, after a file was moved. It seems that there's a little setting that makes all the difference here, one I have enabled and that seems to be required for this to work flawlessly : I assume on Configuration - Advanced you have "Auto-refresh on file system changes" enabled already, and you will have to add "No refresh during file operations" as well.

Don: given this I think this one should be added to commands setting(p) so that the script could ensure it's enabled during its execution.

lukescammell: hmm.. all the time? I have to say that one I don't know, sorry.
Proud XYplorer Fanatic

Post Reply