Possible to create folders from file names?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Vocalpoint
Posts: 177
Joined: 06 Nov 2009 14:01

Possible to create folders from file names?

Post by Vocalpoint »

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
OS: Win 11 24H2 Pro x64 | XY: 27.10.600 (x32)| Display: 1920x1080 @ 60hz

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

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?

Post by Vocalpoint »

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

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

Scripting I assume?
Exactly...
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?

Post by Vocalpoint »

highend wrote:
Scripting I assume?
Exactly...
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.

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

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

how to execute it on a single folder with just a single file
It's meant for selected files, not folders :)
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?

Post by Vocalpoint »

highend wrote:
how to execute it on a single folder with just a single file
It's meant for selected files, not folders :)
Awesome. This works very well.

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

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

is it possible to plant this script on a right click menu spot?
Not possible. At least not directly. But a CFA would be possible:

Code: Select all

|"Put into subfolder" jpg>::load "Put into subfolder.xys";
and you would have to store the script in a file called "Put into subfolder.xys" in your <scripts> folder.

Then you could open such a .jpg with a right click, open with... -> Put into subfolder
Or is my keyboard shortcut the best way to fly?
Probably...
One of my scripts helped you out? Please donate via Paypal

Schuller
Posts: 184
Joined: 02 May 2023 21:08

Re: Possible to create folders from file names?

Post by Schuller »

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

Vocalpoint
Posts: 177
Joined: 06 Nov 2009 14:01

Re: Possible to create folders from file names?

Post by Vocalpoint »

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?
I just use this:

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

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

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?
I'm not sure I get this...

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

Schuller
Posts: 184
Joined: 02 May 2023 21:08

Re: Possible to create folders from file names?

Post by Schuller »

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.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

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

Schuller
Posts: 184
Joined: 02 May 2023 21:08

Re: Possible to create folders from file names?

Post by Schuller »

This works perfect!
Thank you.

After trying this I noticed my scripted column named "Amount" where I have this script
return gettoken (<cc_base>, 2, "$", , 2);
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?

Ex:
*\Mirka Sander $690.55.pdf
return gettoken (<cc_base>, 2, "$", , 2);
will put 690.55 into the "Amount" custom column

but when using
return gettoken (<cc_base>, 2, "$", , 2);
on the folder *\Mirka Sander $690.55\ it only returns 690

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Possible to create folders from file names?

Post by highend »

Code: Select all

$cc = (<cc_isfolder> == 0) ? <cc_base> : <cc_name>;
  return gettoken($cc, 2, "$", , 2);
or in short form

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

Post Reply