Luis Diaz
asked on
VB Script: Dynamically rename files based on last date modified.
Hello experts,
I am looking for a script that rename files in a specific folder based on the lastdatemodified
Ex: File1.csv--->lastdatetemod ified(2014 ,02,24)
File2.csv--->lastdatetemod ified(2014 ,12,25)
Result after I run the script
File1_20140224.csv
File2_20141225.csv
Imagine that I modifie now File 1 and I re-run the script.
The result should be the following:
File1_20150224.csv
File2_20141225.csv
Additionally I would like to add the following log loops (for errors, I would like to output a log.txt file):
1-If folder path doesn't finish "\" add a back slash.
2- If the folder setup in which the script should rename the files doesn't exist echo.Wscript "the Folder with the following path doesn't exist"
3-If the files.count=0 echo.Wscript "Folder doesn't contains files to rename"
I am looking for a script that rename files in a specific folder based on the lastdatemodified
Ex: File1.csv--->lastdatetemod
File2.csv--->lastdatetemod
Result after I run the script
File1_20140224.csv
File2_20141225.csv
Imagine that I modifie now File 1 and I re-run the script.
The result should be the following:
File1_20150224.csv
File2_20141225.csv
Additionally I would like to add the following log loops (for errors, I would like to output a log.txt file):
1-If folder path doesn't finish "\" add a back slash.
2- If the folder setup in which the script should rename the files doesn't exist echo.Wscript "the Folder with the following path doesn't exist"
3-If the files.count=0 echo.Wscript "Folder doesn't contains files to rename"
ASKER
Hello Rob,
I tried to run your script and here are my remarks:
1-I have an error message (line 35 char 6) file not found.(I re-check folders variable and all is good)
2-The log file just make apears the following line:"2/25/2015 9:29:19 PM: Script started"
3-The file rename has been performed just for files which have a datemodified that contains contains current month (02/2015).
Thank you again for your help.
I tried to run your script and here are my remarks:
1-I have an error message (line 35 char 6) file not found.(I re-check folders variable and all is good)
2-The log file just make apears the following line:"2/25/2015 9:29:19 PM: Script started"
3-The file rename has been performed just for files which have a datemodified that contains contains current month (02/2015).
Thank you again for your help.
Oh whoops. On line 35, it can't find objFile.Path because it doesn't exist after the Move is executed. I have corrected that. Can you try again please?
ASKER
Hello Rob,
Do you have the revised verion of the script?
Do you have the revised verion of the script?
Sorry, forgot to mention that I updated the original script to correct the error. You can copy the code from above and try again.
Rob.
Rob.
ASKER
Ok, thank you for this revised version.
I tested and I have some remarks:
1-Everything is ok till it got permission refused, I think (quite sure) this is caused because the script trying to rename the LogFile.txt, and writing on it at the same time. (I put the LogFile.txt in the same folder ;-)
2-Is there a way to add an additional loop excluding the logFile of the rename, and an error line "the file cannot be renamed, someone is editing the file additionnally if an error is encountered the script should continue to the next file. After that this script will be a 10/10 without any doubt§
I tested and I have some remarks:
1-Everything is ok till it got permission refused, I think (quite sure) this is caused because the script trying to rename the LogFile.txt, and writing on it at the same time. (I put the LogFile.txt in the same folder ;-)
2-Is there a way to add an additional loop excluding the logFile of the rename, and an error line "the file cannot be renamed, someone is editing the file additionnally if an error is encountered the script should continue to the next file. After that this script will be a 10/10 without any doubt§
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Rob,
I have tested and it works perfectly!
Thank you!
I have tested and it works perfectly!
Thank you!
Great! If you ever need help understanding the code, let me know.
Thanks for the grade.
Rob.
Thanks for the grade.
Rob.
Regards,
Rob.
Open in new window