Renaming Unknown files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jfrish
Posts: 3
Joined: 10 Dec 2014 07:09

Renaming Unknown files

#1 Post by jfrish » 10 Dec 2014 07:13

So I have a program generating txt files sequencially. I need to rename these files once another process runs, so that the process doesn't grab the same file more than once. If I have a file generating A1####.txt, Is it possible to rename these files using a wildcard bat script?

I tried something like:
ren "C:\Folders\AH*.txt" "C:\Folders\AH*.archive"

but get an invalid syntax... any ideas?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Renaming Unknown files

#2 Post by Squashman » 10 Dec 2014 07:22

Code: Select all

@echo off
pushd "C:\Folders"
FOR %%G IN (AH*.txt) do ren "%%~G" "%%~nG.archive"
popd

jfrish
Posts: 3
Joined: 10 Dec 2014 07:09

Re: Renaming Unknown files

#3 Post by jfrish » 10 Dec 2014 08:23

%%G was unexpected at this time.

When I run what you gave me... is there something else I need to do prior to that command to identify the %%G parameter?

can you explain what the pushd and pops commands are doing?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Renaming Unknown files

#4 Post by Squashman » 10 Dec 2014 08:52

The code I gave you is supposed to be run from a batch file and not the CMD prompt.

The PUSHD command sets the working directory to where your files are located.
The POPD command resets the working directory back to where the original working directory was.

jfrish
Posts: 3
Joined: 10 Dec 2014 07:09

Re: Renaming Unknown files

#5 Post by jfrish » 10 Dec 2014 09:00

perfect!

Thanks Squash!

Post Reply