rename problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mario.marra
Posts: 1
Joined: 28 Nov 2011 04:39

rename problem

#1 Post by mario.marra » 28 Nov 2011 05:53

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.

aGerman
Expert
Posts: 4712
Joined: 22 Jan 2010 18:01
Location: Germany

Re: rename problem

#2 Post by aGerman » 28 Nov 2011 17:11

The help for REN is
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

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: rename problem

#3 Post by orange_batch » 29 Nov 2011 03:36

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.

Post Reply