jwragg
asked on
copy folder and rename\append files contained with date
hiya :o)
i have set up a batch file to copy a file across from one server to another then append that file with the current date.
now the department that asked me to develop that would like it changing slightly. they would like a whole folder copying across then all the files within that folder appended with the current date...so the file in folderA is called file.txt and the file in folderB is called file-08092005.txt
at the moment, i dont know what the file extension is of the files that need copying just i know they need to be appended and going from one server to another.
if you need anymore information, please let me know and ill answer the best i can
thanks in advance
i have set up a batch file to copy a file across from one server to another then append that file with the current date.
now the department that asked me to develop that would like it changing slightly. they would like a whole folder copying across then all the files within that folder appended with the current date...so the file in folderA is called file.txt and the file in folderB is called file-08092005.txt
at the moment, i dont know what the file extension is of the files that need copying just i know they need to be appended and going from one server to another.
if you need anymore information, please let me know and ill answer the best i can
thanks in advance
ASKER
sorry i wasnt clear.
yeah, your example is exactly what i need; called file1.blah in folder1 then is renamed to file1_08092005.blah
hope it makes more sense now
yeah, your example is exactly what i need; called file1.blah in folder1 then is renamed to file1_08092005.blah
hope it makes more sense now
ASKER
god its been a long day at work...this is what i meant to say above:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
sorry i wasnt clear.
yeah, your example is exactly what i need; called file1.blah in folder1 then is renamed to file1_08092005.blah in folder2
hope it makes more sense now
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
--------------------------
sorry i wasnt clear.
yeah, your example is exactly what i need; called file1.blah in folder1 then is renamed to file1_08092005.blah in folder2
hope it makes more sense now
--------------------------
Here is a script that will should work. It will copy all files, NOT going into sub-folders, if any exist.
@echo off
setlocal
::Change these as necessary
set Source=d:\temp\
set Dest=d:\temp2\
set Today=%date:~4,2%%date:~7, 2%%date:~1 0,4%
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
::Remove the echo from the next line to do the actual copy
echo copy "%FilePath%" "%Dest%%FileName%_%Today%% FileExt%"
goto :eof
@echo off
setlocal
::Change these as necessary
set Source=d:\temp\
set Dest=d:\temp2\
set Today=%date:~4,2%%date:~7,
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
::Remove the echo from the next line to do the actual copy
echo copy "%FilePath%" "%Dest%%FileName%_%Today%%
goto :eof
oh, both Source and Dest *MUST* end in a backslash
ASKER
thanks for the script but it hasnt worked for me; this is what i have in my batch file at the moment:
@echo off
setlocal
::Change these as necessary
set Source=c:\temp\
set Dest=c:\temp2\
set Today=%date:~4,2%%date:~7, 2%%date:~1 0,4%
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
::Remove the echo from the next line to do the actual copy
copy "%FilePath%" "%Dest%%FileName%_%Today%% FileExt%"
goto :eof
im testing it locally at the moment therefore i am using C as my source and destination. batch file is being ran from C root.
im probs making a right n00b mistake but i cant see where i might have misunderstood your comments
@echo off
setlocal
::Change these as necessary
set Source=c:\temp\
set Dest=c:\temp2\
set Today=%date:~4,2%%date:~7,
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
::Remove the echo from the next line to do the actual copy
copy "%FilePath%" "%Dest%%FileName%_%Today%%
goto :eof
im testing it locally at the moment therefore i am using C as my source and destination. batch file is being ran from C root.
im probs making a right n00b mistake but i cant see where i might have misunderstood your comments
Do the source and dest directories exist?
Do you get an error message?
If you leave the echo on the copy line, do you get any output?
Do you get an error message?
If you leave the echo on the copy line, do you get any output?
ASKER
yeah source and dest dir exist
no error message; ive even tried adding a 'pause' at the end to see if there is an message but the windows closes still
if i leave echo on copy line, still no output.
no error message; ive even tried adding a 'pause' at the end to see if there is an message but the windows closes still
if i leave echo on copy line, still no output.
try going into a command window, and then run it. This way if there is any output, the window won't close when the program is done. Also, this has extra output, just to see if there is anything.
Are there any files in the source directory?
@echo off
setlocal
::Change these as necessary
set Source=c:\temp\
set Dest=c:\temp2\
set Today=%date:~4,2%%date:~7, 2%%date:~1 0,4%
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
echo Checking: %FilePath%
::Remove the echo from the next line to do the actual copy
echo copy "%FilePath%" "%Dest%%FileName%_%Today%% FileExt%"
goto :eof
Are there any files in the source directory?
@echo off
setlocal
::Change these as necessary
set Source=c:\temp\
set Dest=c:\temp2\
set Today=%date:~4,2%%date:~7,
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1
set FileName=%~n1
set FileExt=%~x1
echo Checking: %FilePath%
::Remove the echo from the next line to do the actual copy
echo copy "%FilePath%" "%Dest%%FileName%_%Today%%
goto :eof
ASKER
arr well i tried adding the pause command before the 'goto :eof' part and i get the error message
"the system cannot find the path specified" about 5 times (theres 5 files in the temp directory)
but the path DOES exist...honest!
"the system cannot find the path specified" about 5 times (theres 5 files in the temp directory)
but the path DOES exist...honest!
ASKER
oo theres more; if i leave the 'echo' in and the 'pause' i get the following messages (still no copy though)
copy "C:\temp\test1.txt" "C:\temp2\test1_9/00.txt"
copy "C:\temp\test2.txt" "C:\temp2\test2_9/00.txt"
copy "C:\temp\test3.txt" "C:\temp2\test3_9/00.txt"
copy "C:\temp\test4.txt" "C:\temp2\test4_9/00.txt"
copy "C:\temp\test5.txt" "C:\temp2\test5_9/00.txt"
obv its muddled somewhere me thinks O_o
copy "C:\temp\test1.txt" "C:\temp2\test1_9/00.txt"
copy "C:\temp\test2.txt" "C:\temp2\test2_9/00.txt"
copy "C:\temp\test3.txt" "C:\temp2\test3_9/00.txt"
copy "C:\temp\test4.txt" "C:\temp2\test4_9/00.txt"
copy "C:\temp\test5.txt" "C:\temp2\test5_9/00.txt"
obv its muddled somewhere me thinks O_o
ASKER
and running it within an already open command windows gives me the error messages already noted above.
It looks like it is the date part
Run this from the command line to see your date formatting
echo %date%
Run this from the command line to see your date formatting
echo %date%
ASKER
im from the UK so doing that command brings me the date like:
08/09/2005
08/09/2005
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
man you are a star - the code above works perfectly once i remove the 'echo' near the bottom - leaving it in place looks like it does the copy but dosent actually put the files in the folder.
thanks very much for your help - much appreciated!
:o)
thanks very much for your help - much appreciated!
:o)
no problem, thanks for the grade :)
the echo makes it print the command to the screen without actually doing it.... so you can see if the copies are what you want. glad it's working!
the echo makes it print the command to the screen without actually doing it.... so you can see if the copies are what you want. glad it's working!
For example, if this is your FROM server
FolderA\file1.txt
FolderA\file2.txt
FolderA\file3.txt
Is this what you would want on your TO server
FolderB\file1_08092005.txt
FolderB\file2_08092005.txt
FolderB\file3_08092005.txt