Hi everyone.
I have a remote server that contains files, named as follows:
*BLABLA_2018May01.txt
*BLABLA_2018May02.txt
*BLABLA_2018May03.txt
What command can I use to rename the files as follows: *May* -> *05* ; *Jun* -> *06*
*BLABLA_20180501.txt
*BLABLA_20180502.txt
*BLABLA_20180503.txt
I'm able to navigate to the correct folder and list the contents, but replacing the strings in filenames is what's causing me headaches.
Any help in achieving the above effect is highly appreciated.
Thanks everyone.
I have a remote server that contains files, named as follows:
*BLABLA_2018May01.txt
*BLABLA_2018May02.txt
*BLABLA_2018May03.txt
What command can I use to rename the files as follows: *May* -> *05* ; *Jun* -> *06*
*BLABLA_20180501.txt
*BLABLA_20180502.txt
*BLABLA_20180503.txt
I'm able to navigate to the correct folder and list the contents, but replacing the strings in filenames is what's causing me headaches.
Any help in achieving the above effect is highly appreciated.
Thanks everyone.
Last edited by castor_bg on 08 Aug 2018, 15:29, edited 1 time in total.
Hi,
There are two new commands in the ScriptFTP 4.6 Beta to handle text strings that can be helpful for this. The commands are named TEXTINDEXOF and TEXTREPLACE, they are not documented yet (there is no help page for them in this website) but I have left you an example below.
The 4.6 Beta can be downloaded from here:
https://www.ScriptFTP.com/beta
There are two new commands in the ScriptFTP 4.6 Beta to handle text strings that can be helpful for this. The commands are named TEXTINDEXOF and TEXTREPLACE, they are not documented yet (there is no help page for them in this website) but I have left you an example below.
The 4.6 Beta can be downloaded from here:
https://www.ScriptFTP.com/beta
FTP Script
- $filename = "*BLABLA_2018May03.txt"
- # If we find Jan in the filename replace with 01
- $new_filename = TEXTREPLACE($filename,"Jan","01")
- # If we find Feb in the filename replace with 02
- $new_filename = TEXTREPLACE($filename,"Feb","02")
- # If we find Mar in the filename replace with 03
- $new_filename = TEXTREPLACE($filename,"Mar","03")
- # If we find Apr in the filename replace with 04
- $new_filename = TEXTREPLACE($filename,"Apr","04")
- # If we find May in the filename replace with 05
- $new_filename = TEXTREPLACE($filename,"May","05")
- # And so on for Jun, Jul...
liked Script FTP? Try our other product Email Parser
Hello there.
Thanks for your quick answer, but I can't seem to get it working. I tried it on a single file and this is the output I'm getting:
TEXTINDEXOF("PRIMEX.Admin.2018Aug01.txt","Aug")
Finding Aug in PRIMEX.Admin.2018Aug01.txt
Text found on position 17
TEXTREPLACE("PRIMEX.Admin.2018Aug01.txt","Aug","08")
Replacing Aug in PRIMEX.Admin.2018Aug01.txt with 08
Then, when I check the file it's still with the old name.
I've upgraded to the version above.
Thanks for your quick answer, but I can't seem to get it working. I tried it on a single file and this is the output I'm getting:
TEXTINDEXOF("PRIMEX.Admin.2018Aug01.txt","Aug")
Finding Aug in PRIMEX.Admin.2018Aug01.txt
Text found on position 17
TEXTREPLACE("PRIMEX.Admin.2018Aug01.txt","Aug","08")
Replacing Aug in PRIMEX.Admin.2018Aug01.txt with 08
Then, when I check the file it's still with the old name.
I've upgraded to the version above.
Hi,
You need to actually change the file name, not only the variable that holds the file name. This is done with RENAMEFILE (if it is a remote file) or EXEC("rename ......") if it is a local file. If you post your script here I can show you how. You can also post only the part of the script related to this, for privacy.
You need to actually change the file name, not only the variable that holds the file name. This is done with RENAMEFILE (if it is a remote file) or EXEC("rename ......") if it is a local file. If you post your script here I can show you how. You can also post only the part of the script related to this, for privacy.
liked Script FTP? Try our other product Email Parser
Hi, everyone.
Thanks to the much appreciated help from the Support I was able to get it working.
Thanks everyone.
Thanks to the much appreciated help from the Support I was able to get it working.
Thanks everyone.
- All times are UTC -