Batch rename - need help renaming files

June 20, 2011 at 14:30:50
Specs: Windows XP, 2.66GHz/2.00GB
Thanks in advance for your help - I am relatively new to batch, so this may be simple to write, but here is my problem. I am operating in Windows XP and using batch file to call another program to create two files, and I need to rename one of those files. I also use this batch to erase one of the files the embedded script creates and move the renamed file

I have a batch which executes a script in an application which deposits two files to a file folder


The KHZ061711 will always be in the format KHZMMDDYY - where MM = month in two digits, DD = day in two digits, and YY = year in two digits.

I need to rename the KHZMMDDYY.txt to KHZMMDDY.txt - where the first "Y" from the year is dropped from the new file name.

Here is my attempt so far - I can rename the text file with new strings like "test", but I cannot figure out how to eliminate just one letter from the file name.

cd C:\application\users\brian\

C:\application\application.exe SCRIPT mlam.scr -exit

cd c:\application\users\brian\testing\

del mlam.txt

rename khz*.txt khztest.txt
(REM would like this to be something like:
rename KHZabcdef.txt KHZabcdf.txt - where the "e" is dropped from the new file name)

move c:\application\users\brian\testing\khztest.txt c:\axys3\users\

Any help would be greatly appreciated

See More: Batch rename - need help renaming files

Report •

June 20, 2011 at 18:48:47

@echo off
color 1f
set /p name=name:
set /p newname=newname:
ren %name%.txt %newname%.txt

Hope that works.

Also, if you are just starting in BATCH, I found the MS-DOS users guide for Windows 95 helpful for batch files. It explains all of the commands and what they do.

Report •

June 21, 2011 at 07:56:13
Thanks for your help.

That fix works, but it makes the process manual, and I was hoping to automate this process so that the batch removes the single character from the file name automatically without user input. I am not sure if this is possible, but if it is that would be the best solution for this particular endeavor.

Report •

Related Solutions

Ask Question