I need help with this...
and if you could, when replying, add REM with notes to explain each step, I would REALLY appreciate it. I have Googled and Googled without success - and when I do find scripts, I do not understand the majority of what each line is trying to accomplish...
this is what I have:
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
copy "C:\Documents and Settings\MyName\Desktop\Test Files Folder\"*.* "E:\TEST Files BKUP folder\"/v
ren "E:\TEST Files BKUP folder\"*.* *"_%date%"_".*
my results:
Test File 1.xlsx_08042010_
what I want:
Test File 1_08042010_.xlsx or whatever the appropriate file extension
In all honesty - I do not even understand the set date code (what DELIMS are, %, tokens,...) - but it has been working for me when I only have a single file to backup.
Copy entire folder THEN rename each file with appended date
Moderator: DosItHelp
-
- Posts: 4
- Joined: 04 Aug 2010 10:43
Re: Copy entire folder THEN rename each file with appended d
It seems to me that the output of date /t is ddd MM/DD/YYYY in your case. So forget the first for loop, you probably don't need it. The second is interresting.
You process the output of date /t. Delims means, which characters are the data separators for your processing. As you can see it's Slash and Space. So the output is splitted to 4 separate parts: ddd, MM, DD and YYYY. The tokens are the parts (2 until 4 in your case) which will be assigned to the dynamic variables, starting with %%a. Finally you will find MM in %%a, DD in %%b and YYYY in %%c. After "do" set these parts to variable date (but this name is not a good one, because it still exists into the cmd environment before).
Rename the files after copying is inconvenient. You need a for loop to separate the file name and the file extension. You could also use the copy command to rename the files in one step.
Into the second for loop %%a is the found file, %%~na is only the file name and %%~xa is only the file extension.
Regards
aGerman
You process the output of date /t. Delims means, which characters are the data separators for your processing. As you can see it's Slash and Space. So the output is splitted to 4 separate parts: ddd, MM, DD and YYYY. The tokens are the parts (2 until 4 in your case) which will be assigned to the dynamic variables, starting with %%a. Finally you will find MM in %%a, DD in %%b and YYYY in %%c. After "do" set these parts to variable date (but this name is not a good one, because it still exists into the cmd environment before).
Rename the files after copying is inconvenient. You need a for loop to separate the file name and the file extension. You could also use the copy command to rename the files in one step.
Code: Select all
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set datestamp=%%a%%b%%c
pushd "C:\Documents and Settings\MyName\Desktop\Test Files Folder"
for /f "delims=" %%a in ('dir /a-d /b *.*') do (
copy "%%a" "E:\TEST Files BKUP folder\%%~na_%datestamp%_%%~xa" /v
)
popd
Into the second for loop %%a is the found file, %%~na is only the file name and %%~xa is only the file extension.
Regards
aGerman
-
- Posts: 4
- Joined: 04 Aug 2010 10:43
Re: Copy entire folder THEN rename each file with appended d
You are AWESOME!!
Thank you so much - it worked perfectly.
I do still have several questions - but no time right now.
(more of the how it works, so I can hopefully understand better/ learn...)
I will reply again this evening.
Thank you!!
Thank you so much - it worked perfectly.
I do still have several questions - but no time right now.
(more of the how it works, so I can hopefully understand better/ learn...)
I will reply again this evening.
Thank you!!
-
- Posts: 4
- Joined: 04 Aug 2010 10:43
Re: Copy entire folder THEN rename each file with appended d
aGerman -
I went through each part of the code and identified what everything was doing (from your comments and lots of Google) - so I now pretty much understand it.
You see what happens when I just copy the code and do not understand it - for example my first 2 lines setting the date variable.
Thank you so much - this was extremely helpful to me!
I went through each part of the code and identified what everything was doing (from your comments and lots of Google) - so I now pretty much understand it.
You see what happens when I just copy the code and do not understand it - for example my first 2 lines setting the date variable.
Thank you so much - this was extremely helpful to me!
-
- Posts: 4
- Joined: 04 Aug 2010 10:43
Re: Copy entire folder THEN rename each file with appended d
okay - that was short-lived...
i'm back
now, say my folder
C:\Documents and Settings\MyName\Desktop\Test Files Folder
also had subfolders with files in them
would I be able to copy and rename/date append all of the files in the subfolders as well?
tia!
i'm back
now, say my folder
C:\Documents and Settings\MyName\Desktop\Test Files Folder
also had subfolders with files in them
would I be able to copy and rename/date append all of the files in the subfolders as well?
tia!
Re: Copy entire folder THEN rename each file with appended d
Should work similar. The question is from where to where would you copy the files?
Regards
aGerman
Regards
aGerman