Hi,
i need to rename a lot of files created with NTBackup.
Each files name is Backupxx.log and i want to rename them in Backupyearmonthdayhhmmsec.log.
From a dos code founded in this forum, i've written the following code:
@echo off
for %%i in (*.log) do (set fname=%%i) & call :rename
goto :eof
:rename
set str=%fname%
set str=%str:.log=%
for /f "tokens=2-9 delims=/:., " %%A in ("%date%:%time: =0%") do set "UNIQUE=%%C%%A%%B%%D%%E%%F%%G%%H"
::echo.%str:~0,6%%UNIQUE%.log
set newFIle=c:\templog\%str:~0,6%%UNIQUE%.log
ren "c:\templog\%str%.log" "%newFIle%"
echo.%newFIle%
echo.%str%templog\%str%.log" "%newFIle%"
::wait for having unique file name
ping -n 2 localhost > nul
goto :eof
::-SethHoyt
I have the following error:
C:\templog>prefix1.bat
Sintassi del comando errata.
c:\templog\Backup11112011501981.log
Backup05
Sintassi del comando errata.
c:\templog\Backup11112011502095.log
Backup06
Sintassi del comando errata.
c:\templog\Backup11112011502200.log
Backup07
Sintassi del comando errata.
c:\templog\Backup11112011502305.log
Backup08
Sintassi del comando errata.
c:\templog\Backup11112011502409.log
Backup09
Sintassi del comando errata.
c:\templog\Backup11112011502514.log
Backup10
the code runs on a xp machine.
Thank you in advance.
Mario.
rename problem
Moderator: DosItHelp
Re: rename problem
The help for REN is
The last sentence shows your fault. You must not specify the drive and path in the second argument. Only the new file name is supported.
Regards
aGerman
Renames a file or files.
RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.
Note that you cannot specify a new drive or path for your destination file.
The last sentence shows your fault. You must not specify the drive and path in the second argument. Only the new file name is supported.
Regards
aGerman
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: rename problem
Adding my 2 cents to aGerman's reply, this behaviour is technically a good thing, because if you intend to rename the file and move it to another location, just use the move command instead. :P In your case you aren't, so just fix the argument's path as he said.