Using DOS Rename FIles with random file names

Windows / Dos
August 2, 2009 at 04:16:54
Specs: Windows XP, PIII
I have a file named:


Which I would like to have renamed to :


I would like to have this done via a batch file.

See More: Using DOS Rename FIles with random file names

Report •

August 2, 2009 at 08:16:09
It is not allowed to use : as character in file names, so what you want can't be done ever under XP.

Report •

August 2, 2009 at 08:56:34
Other characters you are not allowed to use include:
< > " / \ | ? *


Report •

August 2, 2009 at 09:20:12
The file name would have random entries for the bellow:



I would like to have the batch file read the file name and rename it without placing the values above within the batch file, similar to passing a variable.

Report •

Related Solutions

August 2, 2009 at 09:40:38
Renaming using : is absolutely forbidden either you manually enter the char or the operation is performed by a script or program. If you want to use instead of : e.g. - that can be done, but a rule to select the files is needed. Does the folder contain these files only?

Report •

August 2, 2009 at 11:27:40
I would like to run either a batch file or a script to rename a file once the file is found (only files relating to this process are within this directory ex: c:\Dollar) and execute the batch file or script to rename the file, once that action is done, I plan on using another process (job file scheduler) to grab the file and process it. I can't use the scheduler directly to rename the file, because it does not have an option to accept the original naming convention of the file, hence why I would like to rename it first.

Can you assist with creating a batch file or script file to do this?

Report •

August 2, 2009 at 13:59:03
As I said you can't use : in renaming, so I selected - as HH MM SS separator. The script below, NT batch, renames all files in the directory coded. Example

myren C:\Dollar

The script is not tested, so report *exactly* if anything goes wrong.

:: MYREN.BAT Usage: myren Folder_Name
@echo off & setlocal EnableDelayedExpansion
pushd %*
for /F %%j in ('dir /B /A-D') do (
set file_old=%%j
set file_new=!file_old:~0,8!-!file_old:~8,2!-!file_old:~10,2!-!file_old:~12!
ren !file_old! !file_new!
: End_Of_Batch

Report •

Ask Question