Possible to create folders from file names?
-
Vocalpoint
- Posts: 177
- Joined: 06 Nov 2009 14:01
Possible to create folders from file names?
Been looking at a number of freeware tools out there - but was wondering if XY has the power to allow me to
1. Highlight a group of files (images in this case)
2. Create a folder structure based on specific parts of the file name.
3. Move the highlighted file to the new folder structure
So if I have a file called: The Police - Ghost In The Machine (1981).jpg
Can XY create a folder structure like:
The Police\Ghost In The Machine\The Police - Ghost In The Machine (1981).jpg
Appreciate any tips.
Cheers!
VP
1. Highlight a group of files (images in this case)
2. Create a folder structure based on specific parts of the file name.
3. Move the highlighted file to the new folder structure
So if I have a file called: The Police - Ghost In The Machine (1981).jpg
Can XY create a folder structure like:
The Police\Ghost In The Machine\The Police - Ghost In The Machine (1981).jpg
Appreciate any tips.
Cheers!
VP
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz
Re: Possible to create folders from file names?
Tailored to your specific example...
Code: Select all
foreach($item, "<get SelectedItemsPathNames |>") {
$first = gettoken($item, 1, " - ");
$second = gettoken(gettoken($item, 2, " - "), 1, " (");
moveto "$first\$second", $item, , 2;
}One of my scripts helped you out? Please donate via Paypal
-
Vocalpoint
- Posts: 177
- Joined: 06 Nov 2009 14:01
Re: Possible to create folders from file names?
highend wrote:Tailored to your specific example...
Code: Select all
foreach($item, "<get SelectedItemsPathNames |>") { $first = gettoken($item, 1, " - "); $second = gettoken(gettoken($item, 2, " - "), 1, " ("); moveto "$first\$second", $item, , 2; }
Sweet!
How do I load this and run it. Scripting I assume?
VP
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz
Re: Possible to create folders from file names?
Exactly...Scripting I assume?
One of my scripts helped you out? Please donate via Paypal
-
Vocalpoint
- Posts: 177
- Joined: 06 Nov 2009 14:01
Re: Possible to create folders from file names?
I must admit - I am very new to scripting. And want to make sure I do not run this on a folder with a 1000 files in it to start.highend wrote:Exactly...Scripting I assume?
Any tips on getting this code into the scripting area and some basics on how to execute it on a single folder with just a single file so I can make sure it works?
EDIT: Got it. Assigned a keyboard shortcut. Works beautiful. Much thanks!
VP
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz
Re: Possible to create folders from file names?
It's meant for selected files, not foldershow to execute it on a single folder with just a single file
One of my scripts helped you out? Please donate via Paypal
-
Vocalpoint
- Posts: 177
- Joined: 06 Nov 2009 14:01
Re: Possible to create folders from file names?
Awesome. This works very well.highend wrote:It's meant for selected files, not foldershow to execute it on a single folder with just a single file
Thanks so much! (XY is pretty amazing)
Suggestion/Request - this particular function should be a standard issue right click menu kinda thing. I have been searching for a way to do this for a number years with little real success.
One final question - is it possible to plant this script on a right click menu spot? Or is my keyboard shortcut the best way to fly?
VP
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz
Re: Possible to create folders from file names?
Not possible. At least not directly. But a CFA would be possible:is it possible to plant this script on a right click menu spot?
Code: Select all
|"Put into subfolder" jpg>::load "Put into subfolder.xys";Then you could open such a .jpg with a right click, open with... -> Put into subfolder
Probably...Or is my keyboard shortcut the best way to fly?
One of my scripts helped you out? Please donate via Paypal
Re: Possible to create folders from file names?
Highend,
I'm trying to do something very similar to this except I would like the files that I highlight instead placed into a folder that is created at the same location where the file already exist. Also, would it possible to have the folder that is created have the same created date as the highlighted file?
Thanks
I'm trying to do something very similar to this except I would like the files that I highlight instead placed into a folder that is created at the same location where the file already exist. Also, would it possible to have the folder that is created have the same created date as the highlighted file?
Thanks
-
Vocalpoint
- Posts: 177
- Joined: 06 Nov 2009 14:01
Re: Possible to create folders from file names?
I just use this:Schuller wrote: ↑20 Oct 2024 16:45I'm trying to do something very similar to this except I would like the files that I highlight instead placed into a folder that is created at the same location where the file already exist. Also, would it possible to have the folder that is created have the same created date as the highlighted file?
moveto "<date mm-dd-yyyy>", , , 2
And assign it to a keyboard shortcut (ALT-M)
So - I select a bunch of files, hit ALT-M on the keyboard and the files are instantly moved to a new folder called 10-20-2024.
VP
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz
Re: Possible to create folders from file names?
I'm not sure I get this...I would like the files that I highlight instead placed into a folder that is created at the same location where the file already exist. Also, would it possible to have the folder that is created have the same created date as the highlighted file?
You select just a single file and want it to be moved to a subfolder (that needs to be created and have the same created date as the file)?
How should the subfolder name look like?
And you don't do this with multiple files selected?
One of my scripts helped you out? Please donate via Paypal
Re: Possible to create folders from file names?
I tested this script you have provided here on a user button by selecting a file called "Thule Bike Rack.pdf" that is located within in my "2024 - Receipts" folder(a sub-folder of Receipts) and I hit the user button and it placed that file into a folder structure one level up, outside of my "2024 - Receipts" folder into a structure that looks like this: Receipts\2024\Receipts\Thule Bike Rack\Thule Bike Rack.pdf
In my case, instead of creating a folder structure based on specific parts of the file name, what I would like is for the file that I select in that same "2024 - Receipts" folder to be placed into just one sub-folder of this "2024 - Receipts" folder and simply name this sub-folder as the file name and put that file inside that sub-folder.
Example:
*\2024 - Receipts\Thule Bike Rack.pdf
hit scripted button and this is what I want
*\2024 - Receipts\Thule Bike Rack\Thule Bike Rack.pdf
If the new sub-folder here called Thule Bike Rack can maintain the same creation date that file already had, that would be ideal, if that is not possible, I'll just manually change the folder creation date to match the file.
The ability to select multiple files within the same folder would be ideal.
In my case, instead of creating a folder structure based on specific parts of the file name, what I would like is for the file that I select in that same "2024 - Receipts" folder to be placed into just one sub-folder of this "2024 - Receipts" folder and simply name this sub-folder as the file name and put that file inside that sub-folder.
Example:
*\2024 - Receipts\Thule Bike Rack.pdf
hit scripted button and this is what I want
*\2024 - Receipts\Thule Bike Rack\Thule Bike Rack.pdf
If the new sub-folder here called Thule Bike Rack can maintain the same creation date that file already had, that would be ideal, if that is not possible, I'll just manually change the folder creation date to match the file.
The ability to select multiple files within the same folder would be ideal.
Re: Possible to create folders from file names?
Thanks for the detailed description, this is the belonging script for that task:
Code: Select all
setting "BackgroundFileOps", 0;
foreach($item, <get SelectedItemsPathNames>, <crlf>, "e") {
if (exists($item) == 2) { continue; }
$cDate = filetime($item, "c");
$newPath = gpc($item, "path") . "\" . gpc($item, "base");
moveto $newPath, $item, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
timestamp "c", $cDate, $newPath;
}
One of my scripts helped you out? Please donate via Paypal
Re: Possible to create folders from file names?
This works perfect!
Thank you.
After trying this I noticed my scripted column named "Amount" where I have this script
Ex:
*\Mirka Sander $690.55.pdf
but when using
Thank you.
After trying this I noticed my scripted column named "Amount" where I have this script
only returns everything after the $ for files but not for folders even though I have Files and Folder selected in item type of the custom column. When I add an extension like .pdf to the folder then it will add everything. Is there something to change on this script where it will return the full amount for folders too?return gettoken (<cc_base>, 2, "$", , 2);
Ex:
*\Mirka Sander $690.55.pdf
will put 690.55 into the "Amount" custom columnreturn gettoken (<cc_base>, 2, "$", , 2);
but when using
on the folder *\Mirka Sander $690.55\ it only returns 690return gettoken (<cc_base>, 2, "$", , 2);
Re: Possible to create folders from file names?
Code: Select all
$cc = (<cc_isfolder> == 0) ? <cc_base> : <cc_name>;
return gettoken($cc, 2, "$", , 2);
Code: Select all
return gettoken(<cc_isfolder> == 0 ? <cc_base> : <cc_name>, 2, "$", , 2);
One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club