renaming fails

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
maclovin
Posts: 6
Joined: 21 Jan 2011 04:13

renaming fails

#1 Post by maclovin » 09 Feb 2011 09:56

Hi there!

I need to move my randomized files to another directory. Can anyone help me with the right amount of code to accomplish this?
What I have is this:

REM MOVE TO THE RIGHT DIRECTORY
pushd %tmpDir%

setlocal EnableDelayedExpansion

for /f %%T in ('dir/s/b/a-d *.*') do (
ren "%%T" "!random!%%~nT.kvi" )
move %tmpDir%\*kvi "T:\Program\renamedFiles"

But I can't seem to get this to work, and I am fresh out of ideas :-)

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: renaming fails

#2 Post by avery_larry » 09 Feb 2011 11:06

t:\program\renamedfiles must exist.
probably want to use *.kvi since it's an extension
path probably should be in quotes:

move "%tmpdir%\*.kvi" "t:\program\renamedfiles"

maclovin
Posts: 6
Joined: 21 Jan 2011 04:13

Re: renaming fails

#3 Post by maclovin » 10 Feb 2011 01:18

It is not allowed to use quotes around destination.

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

Re: renaming fails

#4 Post by aGerman » 10 Feb 2011 12:07

maclovin wrote:It is not allowed to use quotes around destination.

Why not?

What error message did your batch file display?

Regards
aGerman

maclovin
Posts: 6
Joined: 21 Jan 2011 04:13

Re: renaming fails

#5 Post by maclovin » 11 Feb 2011 06:32

Thanks for the reply! and the kind help so far.

When I run this ( i have 2 files which I want to rename) :
REM %tmpDir% is defined in end of script

pushd %tmpDir%
setlocal EnableDelayedExpansion
For /F "Tokens=* Delims=" %%T in ('dir/s/b/a-d *.*') do (
ren "%%T" "!random!%%~nT.kvi" )
pause
move "%tmpDir%\*kvi" "C:\renamedFiles"
pause

I get this:

C:\>pushd "C:\temp"

C:\temp>setlocal EnableDelayedExpansion

C:\temp>For /F "Tokens=* Delims=" %T in ('dir/s/b/a-d *.*') do (ren "%T" "!random!%~nT.kvi" )

C:\temp>(ren "C:\temp\22022testret2.kvi" "!random!22022testret2.kvi" )

C:\temp>(ren "C:\temp\testret" "!random!testret.kvi" )

C:\temp>pause
Trykk en tast for å fortsette...

C:\temp>move " "C:\temp"\*kvi" "C:\renamedFiles"
Filename, foldername or volumname syntax is wrong

C:\temp>pause
press to continue

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: renaming fails

#6 Post by jeb » 11 Feb 2011 06:55

Ok, a really hard problem :wink:

Code: Select all

C:\temp>move " "C:\temp"\*kvi" "C:\renamedFiles"
Filename, foldername or volumname syntax is wrong


But wait ... I count 6 quotes, I expected only 4.

jeb

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

Re: renaming fails

#7 Post by aGerman » 11 Feb 2011 08:05

Yes, jeb is absolutely right.

Probably you have a line like this:

Code: Select all

set tmpDir = "C:\temp"

but you should try

Code: Select all

set "tmpDir=C:\temp"


Regards
aGerman

maclovin
Posts: 6
Joined: 21 Jan 2011 04:13

Re: renaming fails

#8 Post by maclovin » 11 Feb 2011 12:03

Thanks alot man! Looks like I might set this in production after all :-)

Have a nice weekend everyone!

maclovin
Posts: 6
Joined: 21 Jan 2011 04:13

Re: renaming fails

#9 Post by maclovin » 14 Feb 2011 01:42

What I ended up using is this:

pushd %tmpDir%
setlocal EnableDelayedExpansion
For /F "Tokens=* Delims=" %%T in ('dir/s/b/a-d *.*') do (
ren "%%T" "!random!%%~nT.kvi" )
pause
move %tmpDir%\*kvi "C:\renamedFiles\"
pause

The only difference between the working code on friday is C:\renamedFiles vs "C:\renamedFiles\"
And oh, of course, my declaration is not set tmp = "\\server\ohshitspaces" but set tmp="\\server\looknospaces"

Looks like it might be working. In production tomorrow :-)

Post Reply