Page 1 of 1

"New item": Change filenames in folder dynamically

Posted: 25 Mar 2013 10:36
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

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

Posted: 25 Mar 2013 11:19
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

...

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

Posted: 25 Mar 2013 11:35
by rhoelzl
Exactly, and I would like the ability to rename some of the files into "a.txt" automatically.

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

Posted: 25 Mar 2013 12:21
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

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

Posted: 15 Apr 2013 11:11
by admin
Too exotic, sorry.