"New item": Change filenames in folder dynamically

Features wanted...
Post Reply
rhoelzl
Posts: 200
Joined: 28 Dec 2009 11:20

"New item": Change filenames in folder dynamically

Post by rhoelzl »

Hi,

in my "New items" folder I have a few folders with several files in them because I need to regularly create copies of those including all the contained files.

(For example: A LaTeX template for letters, consisting of several files: the template LETTER.TEX itself and several font files).

When I create such a new item, then XY asks me, what name I want the new folder to have, which is good.

But of course then the files INSIDE the folder will always have the same name: LETTER.TEX. So I always have to rename them manually.

It would be great if I could give a *special* filename to the files inside a "new items" subfolder (for example XY_FOLDERNAME_HERE.TEX or something similar), and as soon as I create the "new item", the name I give to the folder would ALSO be given those files inside the folder that have XY_FOLDERNAME_HERE as their filename base.

Cheers,
rh

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

Re: "New item": Change filenames in folder dynamically

Post by highend »

If I create a new folder under:
D:\Users\Highend\Tools\XYplorer\Data\NewItems\

named "Testfolder" and additionally create 2 items in that "Testfolder":
1.txt
2.txt

and then rightclick on white space, "New items" -> "Testfolder"

I give that folder the name "a", both files in it will still be called:
1.txt
2.txt

...
One of my scripts helped you out? Please donate via Paypal

rhoelzl
Posts: 200
Joined: 28 Dec 2009 11:20

Re: "New item": Change filenames in folder dynamically

Post by rhoelzl »

Exactly, and I would like the ability to rename some of the files into "a.txt" automatically.

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

Re: "New item": Change filenames in folder dynamically

Post by highend »

Ok, I see.

Until Don implements this function, use this script:

Code: Select all

	$replace = "XY_FOLDERNAME_HERE"; // Edit this one to match the naming rules of your files

	setting "BackgroundFileOps", 0;
	$newItemsFolder = "<xydata>\NewItems";
	$newFolder = inputselect("Select folder template:", folderreport("dirsrel", "r", $newItemsFolder, , , "|"), "|", 0);
	$folderName = input("Enter the new name of the folder to be created", , $newFolder, "s", $newFolder);
	new($folderName, "dir", "$newItemsFolder\$newFolder");
	$items = folderreport("files", "r", "<curpath>\$folderName", "r", , "|");
	foreach ($item, $items, "|") {
		rename s, "$replace/$folderName", , "$item";
	}
You can edit the $replace variable to whatever you like, until your files in your NewItems folders have the same name / contain that part of the name.

E.g. you could also name your files:
Hello_TEMPLATE.TEX
MyFont_TEMPLATE.ttf
etc.

and use
$replace = "TEMPLATE";

which would lead to (let's assume you name the new folder "document":
Hello_document.TEX
MyFont_document.ttf
One of my scripts helped you out? Please donate via Paypal

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

Re: "New item": Change filenames in folder dynamically

Post by admin »

Too exotic, sorry.

Post Reply