Batch File Assistance

Microsoft Windows xp professional w/sp2
March 25, 2010 at 11:55:57
Specs: Windows XP
I would like to create a simple batch file that will copy 5-9 files from a directory on my C:\ to a directory on a mapped network drive. The catch is that the files will need to be renamed by placing the current date in the name. The files cannot overwrite any other files in the target directory.

See More: Batch File Assistance

Report •

#1
March 25, 2010 at 15:14:07
This will get you a variable string with the of the date and time but i need more information on what files you want copied?
Are there other files in that directory that are not to be copied or is it a random 5-9 files? etc.


@echo off
setlocal enabledelayedexpansion
:GETFILENAME
echo %date% > date.txt
echo %time% > time.txt
set strDate=
set strTime=
set strFilename=

for /f "tokens=1,2,3,4 delims=/ " %%A in (date.txt) do (
set strDate=%%A%%B%%C%%D
)
for /f "tokens=1,2,3,4 delims=: " %%A in (time.txt) do (
set strTime=%%A.%%B
)
set strFilename=%strDate%%strTime%


Report •

#2
March 26, 2010 at 04:58:42
Thank You for the rapid response. There are no other files in the folder. The files are downloaded daily and I have to go in and rename them and then move them. After I move them the original file is empty. The files need to keep the same file name, but add just the date (not time) to the name. For example test.txt would become test032610.txt

Thank you again.


Report •

#3
March 28, 2010 at 22:03:28
This will get the current date and copy all your files from the source directory to the destination directory.


@echo off
setlocal enabledelayedexpansion
:GETFILENAME
echo %date% > date.txt
set strDate=
set strFilename=

for /f "tokens=1,2,3,4 delims=/ " %%A in (date.txt) do (
set strDate=%%A%%B%%C%%D
)
del /q date.txt
set strFilename=%strDate%

:COPY
if exist ren.txt del ren.txt
dir /A:-d /B "YOURSOURCEDIR">> ren.txt
for /f "tokens=1 delims=," %%A in (ren.txt) do (
copy "YOURSOURCEDIR\%%A" "YOURDESTINATIONDIR"
ren "YOURDESTINATIONDIR\%%A" "!strfilename!%%A"
)
del /q ren.txt


Report •
Related Solutions


Ask Question