|
Answer» I have read several posts and I cannot FIND it.
I have output from a switch that runs 24/7 The output file is named data by the switch automatically no extension
every 4 hours I have a batch file that runs to move the file and convert it to a TXT file it is then imported into my database
So I have a path like this
c:\output\data.txt
the next batch file I want to run would copy the data.txt to c:\output\history and give it a random name.
The copy, move and create random name file would be created every 4 hours
I am just using Scheduled tasks to run these batch files.
I cannot find the syntax to copy, move and rename. I found several examples like this that should work but I am not sure how to use it.
Set newname=%RANDOM%.%RANDOM% ren %1 %newname% Del %newname% pause exit
I have used only very basic commands copy c:\output\data c:\output\data.txt this line saved in update.bat
How would a rename.bat look
Help. Tinagive this a try and let me know if you have any issues. the new file name will be in the FORM of MM-DD-YYYY_Hours.Minutes.Seconds.txt
example: 07-16-2009_10.39.41.txt
Code: [Select]ECHO OFF CLS
REM SETTING UP VARS FOR USE SET TXTNAME=DATA
SET DATALOC=c:\OUTPUT
SET NDATE=%DATE:~4,10% SET MDATE=%NDATE:~0,2% SET DDATE=%NDATE:~3,2% SET YDATE=%NDATE:~6,4% SET NDATE=%MDATE%-%DDATE%-%YDATE%
SET NTIME=%TIME:~0,-3% SET HTIME=%NTIME:~0,2% SET MTIME=%NTIME:~3,2% SET STIME=%NTIME:~6,2% SET NTIME=%HTIME%.%MTIME%.%STIME%
SET NEWNAME=%NDATE%_%NTIME%
cd \ CD %DATALOC% REM CHECK FOR HISTORY FOLDER IF NOT EXIST "c:\OUTPUT\history" MKDIR "c:\OUTPUT\history"
MOVE /Y "c:\OUTPUT\data.txt" "c:\OUTPUT\HISTORY"
CD HISTORY
RENAME "c:\OUTPUT\HISTORY\data.txt" "%NEWNAME%.txt" WOW!
EXACTLY WHAT I NEEDED.
HOW DO I THANK YOU FOR THIS? TINAI found it and clicked on it.
Thanks again, Tina
|