phillyman2004 Posted June 6, 2005 Posted June 6, 2005 I am looking for a way to rename a file with the current dateBasically...Take MasterTracker.xlsand make a copy , and rename it to June 6th.xlsand have this batch file execute each night and move the old date to an archive folder and recreate the file for that dayIs it possible ??Rob
Martin Zugec Posted June 6, 2005 Posted June 6, 2005 I will write it for you... Would you be satisfied with script for parameters, likeRename2Date.bat file_to_rename.exe?
Martin Zugec Posted June 6, 2005 Posted June 6, 2005 Here you go (didnt have a chance to try it, so I am waiting for your feedback)@Echo offrem Reading input fileIf "%1" EQU "" ( Echo You must use parameter - name of file to rename. Goto :EOF ) ELSE ( Set strFile2Rename=%1 )If not exist %strFile2Rename% ( Echo %strFile2Rename% was not found! Goto :EOF )For /f "usebackq delims=. tokens=1,2" %%i IN (`echo %strFile2Rename%`) Do Set strFileExtension=%%jrem Main codecall:ConvertDatecall:RenameFileGoto:EOF:ConvertDate rem Reading date format, converting and saving datefor /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do ( set A=%%a&set B=%%b&set C=%%c)set t=2&if "%date%z" LSS "A" set t=1for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do ( for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do ( set dd=%%d&set mm=%%e&set yy=%%f))Goto:EOF:RenameFileEcho File %strFile2Rename% will be renamed to %dd%-%mm%-%yy%.%strFileExtension%ren %strFile2Rename% %dd%-%mm%-%yy%.%strFileExtension%
jaclaz Posted June 6, 2005 Posted June 6, 2005 There was another thread about this, with examples posted, here:http://www.msfn.org/board/index.php?showtopic=37572and this is a file I use normally:@echo offif not exist turiweb md turiwebif not exist turiweb\log.log date /t > turiweb\log.logdate /t > turiweb\date.nowtime /t > turiweb\time.nowSet CURRDATE=%TEMP%\CURRDATE.TMPSet CURRTIME=%TEMP%\CURRTIME.TMPDATE /T > %CURRDATE%Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "For /F %PARSEARG% %%i in (%CURRDATE%) Do SET DDMMYYYY=%%j_%%k_%%lEcho Copying file turiweb.xml in turiweb\turiweb_%DDMMYYYY%.xmlif exist turiweb\turiweb_%DDMMYYYY%.xml goto errorif not exist turiweb\turiweb_%DDMMYYYY%.xml copy turiweb.xml turiweb\turiweb_%DDMMYYYY%.xml > nul:OKecho OK,File turiweb_%DDMMYYYY%.xml correctly createdecho OK,File turiweb_%DDMMYYYY%.xml correctly created > turiweb\temp.nowGoto end:errorEcho Error, file turiweb_%DDMMYYYY%.xml already existing, file NOT copiedecho Error, file turiweb_%DDMMYYYY%.xml already existing, file NOT copied > turiweb\temp.now:endcopy turiweb\log.log+turiweb\date.now+turiweb\time.now+turiweb\temp.now turiweb\log.log > nuldel turiweb\*.now > nulpause(the good thing about this one is that keeps a log file)Just change the occurrencies of turiweb and turiweb.xmljaclaz
phillyman2004 Posted June 6, 2005 Author Posted June 6, 2005 I will write it for you... Would you be satisfied with script for parameters, likeRename2Date.bat file_to_rename.exe?<{POST_SNAPBACK}>Very Very Close to what i need , I just need it to leave a the original file alonemy folder should look like this---------------------------MasterTracker.xls <--- MainJune6th.xlsJune7th.xlsJune8th.xls....i dont care about the date format , I plan on executing this batch file every morning at 7am (Windows Scheduler) , to make a new file for that day , and open it
gunsmokingman Posted June 6, 2005 Posted June 6, 2005 Here is one that will rename a text file to the date, just change theextention to suit your needs.It is based on the script i made for folders by date.This will do only 1 file per folder or directory.@echo offcls color F2mode con: Cols=55 Lines=3Title What Year Is It Test 2NLSFUNCSET D1=%date:~-4,10%SET D2=%date:~7,-5%SET D3=%date:~4,-8%SET D4=%date:~0,-10%if exist %D3%-%D2%-%D1%.Txt goto E1 if not exist %D3%-%D2%-%D1%.txt goto W1:W1::mkdir %D3%-%D2%-%D1%if exist *.txt goto W2:w2ren *.txt %D3%-%D2%-%D1%.txtecho.echo File Was Rename to %D3%-%D2%-%D1%.txt Was Made!ping -n 3 127.0.0.1>nulexit:e1echo.echo File Was Already Made!ping -n 3 127.0.0.1>nulThis I added A time Code So it Changes@echo offcls color F2mode con: Cols=55 Lines=3Title What Year Is It Test 2NLSFUNCSET D1=%date:~-4,10%SET D2=%date:~7,-5%SET D3=%date:~4,-8%SET D4=%date:~0,-10%set t1=%time:~-2,8%if exist *.txt goto W2if exist %D3%-%D2%-%D1%-%t1%.Txt goto E1 :w2ren *.txt %D3%-%D2%-%D1%-%t1%.Txtecho.echo File Was Rename to %D3%-%D2%-%D1%-%t1%.Txt Was Made!ping -n 3 127.0.0.1>nulexit:e1echo.echo File Was Already Made!ping -n 3 127.0.0.1>nul
Noise Posted June 6, 2005 Posted June 6, 2005 @smokinggunman,That's very nice use of the date variable, that will come in extremely handy in the future! Thanks. Couple of questions though. Will your script work on Windows 2000? Why are you running nlsfunc?
net_user Posted June 6, 2005 Posted June 6, 2005 try this to renameing a file. from there you can copy to where every you want to.rename "c:\Take MasterTracker.xls" %Date:~-10,2%_%Date:~-7,2%_%Date:~-4,4%.xls
gunsmokingman Posted June 6, 2005 Posted June 6, 2005 NLSFUNC I use this from what i read so it work in other langauges.I have never been able to figure out exacly what it does,It doesnt cause any erors so I left it in.As to windows 2000 I am not sure if it will work, but since it a cmd file,it in therory should work. Maybe some of the more gifted members can explain this NLSFUNC functionbetter then I can.
jaclaz Posted June 6, 2005 Posted June 6, 2005 Not used anymore, it was an OLD dos command:http://www.microsoft.com/resources/documen...us/nlsfunc.mspxjaclaz
Martin Zugec Posted June 7, 2005 Posted June 7, 2005 Same as my ConvertDate function I am using the trick to run date command, it will show you current format (dd-mm-yy) and then parse it to three variables
jaclaz Posted June 7, 2005 Posted June 7, 2005 ...also this might be interesting:http://winadmin.sourceforge.net/warmzip.htmlwaRmZip.wsf v1.6 (Jul 2004) - http://winadmin.sourceforge.net _____Utility to clean up/free up space in a folder (and its subfolders),* compressing files after a certain number of days (with external program)* rotating files after a certain number of days/above a certain size* deleting files and/or empty folders after a certain period of time* moving files to other folders/disksjaclaz
jonathan987 Posted September 20, 2017 Posted September 20, 2017 (edited) Yes offcourse is possible you can change date, extensions or anything you want by using Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org. Edited October 21, 2017 by jonathan987
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now