Discussion Locked

DOS Batch file to rename files

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have about 500 files in a Directory:

d:\directory\subdirectory\somefilename.prg

I need to rename these files to:

d:\directory\subdirectory\smr_somefilename.prg

Is there any way to use DOS or other techniques to avoid manually changing these file names?

9 replies

by otl

According to dos:
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a directory
name, or a combination. If you are moving only one
file, you can also include a filename if you want
to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.

/Y Suppresses prompting to confirm creation of a directory
or overwriting of the destination.
/-Y Causes prompting to confirm creation of a directory or
overwriting of the destination.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

by lo

When I have had same/similar I usually do a DIR >filren.bat (or whatever). Then edit the file and turn it into a batch file. That is a bit of work but easier than one file at a time. If you have access to a 'program editor' VI, EMACS, etc. (not sure what on Win, you can do block cub/copy/paste and do macros/learn sequences that make the job a lot less effort. If you have an editor that will do the work, but not on Win, copy the file to the system, edit and copy back. I do this with Compaq TPU Editor. Also have a QTSR from SemWare that works pretty good on Win (not sure if they are still around, had it for 5+ years I think.

lo

by john cranny

Follow the steps below NOTE commands are enclosed by hashes ###.
1. open a dos prompt & navigate to the right directory.
2. Get a listing of all the file names using this command==###dir /b *.tmp > out.txt###
3. Rename the files==###FOR /F "tokens=1 eol=;" %I in (out.txt) DO ren %I smr_%I###
4. Job done.!!

by Member 21361443

Yeah, but remember the DOS filename limits you to 8 chars.3 chars. I would make a backup copy before you perform this suggestion, by the way. You can simply do this using the following commands (^ = enter): mkdir c:\test^ cd\directory\subdirectory^ for %a in (*.prg) do move %a c:\test\smr_%a^ cd\test^ move *.* c:\directory\sudirectory^ Good luck! Brian

This discussion is closed to new replies.