Rename script
Rename script
Hi, I am a novice and I have a folder with 2000-2500 file and I want rename them with this method:
1. select only the files which name begin with the zero digit (01218.png,054889.png,06566.png and so on)
2. sort them by name
3. rename them with the zero digit as first character name and then a 4digits number sequence (00001.png, 000002.png and so on)
Then I have to make the same thing with file which name begin with the one digit and then with two digit
Is it possible?
1. select only the files which name begin with the zero digit (01218.png,054889.png,06566.png and so on)
2. sort them by name
3. rename them with the zero digit as first character name and then a 4digits number sequence (00001.png, 000002.png and so on)
Then I have to make the same thing with file which name begin with the one digit and then with two digit
Is it possible?
Re: Rename script
I'm serching for... probably is enough a RegExp rename using this: (.{1})(.+)(\..+) > $1$3 (keep first character) plus <#0000> (number sequence) but I can't find the right syntax to joint this espressions. Who can joint them?
Re: Rename script
There is no count something up in a batch regex rename.
Something like this should work:
Something like this should work:
Code: Select all
$files = listfolder(, , 1+4, <crlf>);
$i = 0;
while ($i < 10) {
$selection = regexmatches($files, "^$i.*?(?=\r?\n|$)", <crlf>);
if ($selection) {
$j = 1;
foreach($item, $selection, <crlf>, "e") {
$number = format($j, "0000");
renameitem($i . $number, $item, 1);
$j++;
}
}
$i++;
}
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
Wow, it work perfectly.
Is it possible add the launch of a batch file (C:\Users\MN\Downloads\4L\Elab\1Stitching.cmd) in your code?
Thank you for your help!
Is it possible add the launch of a batch file (C:\Users\MN\Downloads\4L\Elab\1Stitching.cmd) in your code?
Thank you for your help!
Re: Rename script
Look at run or runret() in the script command section of the help file
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
I found the run help and I add the line: run "C:\Users\MN\Downloads\4L\Elab\1Stitching.cmd"; to the end of your code but now seems that the engine script sees two script... but it is not so important, I can lauch manually
Thank you again!
Thank you again!
Re: Rename script
And that looks like?but now seems that the engine script sees two script...
Sounds like a missing indentation for that new line...
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
This is my proof (I'm not a programmer):
Code: Select all
$files = listfolder(, , 1+4, <crlf>);
$i = 0;
while ($i < 10) {
$selection = regexmatches($files, "^$i.*?(?=\r?\n|$)", <crlf>);
if ($selection) {
$j = 1;
foreach($item, $selection, <crlf>, "e") {
$number = format($j, "0000");
renameitem($i . $number, $item, 1);
$j++;
}
}
$i++;
}
run "C:\Users\MN\Downloads\4L\Elab\1Stitching.cmd";
Last edited by gialandra on 04 Feb 2019 00:20, edited 1 time in total.
Re: Rename script
Last line in my last posting...
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
You are right, indent was the problem. Now it works
Last thing: is it possible lock the script work to a fixed folder? I want to run the script from any folder and it should to work always on a fixed folder
Last thing: is it possible lock the script work to a fixed folder? I want to run the script from any folder and it should to work always on a fixed folder
Last edited by gialandra on 04 Feb 2019 10:15, edited 1 time in total.
Re: Rename script
Look up the listfolder() command and its very first argument.
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
From what I understand, but I'm walking in darkness, to reduce the work of the script to only one folder, I have tried to put the path of the folder in your code, but it does not work and i have not found other advice on how to put this path:
$files = listfolder(<C:\Users\5314410\Downloads\CANC\>,, 1+4, <crlf>);
$files = listfolder(<C:\Users\5314410\Downloads\CANC\>,, 1+4, <crlf>);
Re: Rename script
Just put it in single or double quotes.
Code: Select all
$files = listfolder("C:\Users\5314410\Downloads\CANC\",, 1+4, <crlf>);
One of my scripts helped you out? Please donate via Paypal
Re: Rename script
Thanks. Now the syntax is OK, but the result is not what I expect (look at the screenshot): if I launch the script from "C:\Users\MN\Downloads\2\" folder, it doesn't work on files in "C:\Users\MN\Downloads\1\" folder
- Attachments
-
- 2019-02-04_161839.png (18.03 KiB) Viewed 3762 times
Re: Rename script
Yeah, you'd need to add the path for the renameitem() command as well. You should do it like this:
Add a line at the top:
Make sure the path ends with a backslash!
Change the $files line to this afterwards:
Change the renamitem() line to this:
Add a line at the top:
Code: Select all
$folder = "C:\Users\MN\Downloads\1\";
Change the $files line to this afterwards:
Code: Select all
$files = listfolder($folder, , 1+4, <crlf>);
Code: Select all
renameitem($i . $number, $folder . $item, 1);
One of my scripts helped you out? Please donate via Paypal