Dos script to rename files [Solved/Closed]

gbr00435 1 Posts Wednesday August 20, 2008Registration date August 21, 2008 Last seen - Aug 21, 2008 at 11:29 AM - Latest reply:  rajesh kanna
- Jun 3, 2014 at 11:50 AM
Hello,
I would like to know what batch commands I can to to rename files in directory called \\gbr1w001\data_transfer_gb77$

INVPRT_5023949000004_20080818061329_0000979.GB ---> 5023949000004_MSG_IN_20080818061329_0000979.GB

PPRHDR_5000119000006_20080721061424_00000981.GB_m ---> 5000119000006_MSG_IN_20080721061424_00000981.GB_m

SLSRPT_5023949000004_20080721061317_00000978.GB ---> 5023949000004_MSG_IN_20080721061317_00000978.GB

Basically I would like to drop 7 characters at the begining of the file and insert MSG_IN_ after next 14 characters.

Any help on this will be most appreciated.

Thank you
See more 

26 replies

Best answer
26
Thank you
for /r %%x in (%1) do ren "%%x" %2

this will rename file recursively :-)

save in a file give 2 arguments from extension and to extension.

ex: file name is test.bat
command : test *.avi *.bmp

it renames all files with extension avi to bmp (in all subfolders :))

Thank you, satya 26

Something to say? Add comment

CCM has helped 1831 users this month

Navigate to the folder with the files to rename in dos, then run this:

rename *.jpg *.mp3

You'll have to do it one folder at a time. You could probably build a batch file to run this command in every folder under some root folder.
Thanks satya for this this command.
I had some difficult to understand it but now I get it.

Perhaps you should be more explicit for newbies like me.
I would say it like this:

Create a bat file (test.bat, for example) with this command:

for /r %%x in (%1) do ren "%%x" %2 


Then, open cmd.exe and from the test.bat folder run (for example):

test *.avi *.bmp
v nice sol;)
thnx:)
Hi Satya,
Is there a way to rename the files with spaces. For example, how do I rename 12345-020-111.pdf to 12345-020-111_Rev A.pdf. There is a space in between Rev and A.
How to change 00001_A-01.txt, 00001_A-02.txt to 00001_b-01.txt, 00001_b-02.txt
2
Thank you
Heres my example of renameing a folder in a directory supplied by the user in a batch file:

@echo off
ECHO Auto Profile Reset by AG
:begin
SET /p variable=[Enter Workstation ID]
SET /p userid=[Enter User ID]
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b
if exist "\\%variable%\C$\documents and settings\" goto exist
echo PATH NOT FOUND... please try again
pause
goto begin
:exist
echo PATH CONFIRMED
pushd \\%variable%\C$\documents and settings\
goto skipit
:notfound
SET /p userid=[Enter User ID]
:skipit
if exist "\\%variable%\C$\documents and settings\%userid%" goto found
echo ID NOT FOUND... please re-enter
pause
goto notfound
:found
Echo modifying...
rename "%userid%" $"%userid%"$"%XDate%"$
Echo ***SUCCESS***
popd
Echo $%userid%$%XDate%$
pause
1
Thank you
@Sen,

is it possible to validate the type of output from ping? Ia dmit I haven't yet tested, but it seems the above will trigger a 'yes' even if the output is timeout, packet response or no host?

Maybe pattern matching as the output is always the same?

Cheers,
Hi Eramus:

Yes, You are right. The original posted question was "if the result give reply then goto another command". So, I assumed the poster was encountering a situation where there was absolutely no output.

I typically look for lost packets such as ".... Lost = 0 ...". So to extract the first numberafter "Lost =", I use
something like the following.

# START SCRIPT
var str output
system ping "10.10.10.1" > $output
# Strip off output upto "Lost = ".
stex -c "^Lost = ^]" $output > null
# Extract the first word.
var str word ; wex "1" $output > $word
# Convert to integer
var int lostcount ; set $lostcount = makeint(str($word))
if ($lostcount > 0)
do
# Yes, packets were lost.
# Insert your additional code here.
done
# END SCRIPT

Sen

The above script is in biterscripting ( http://www.biterscripting.com/install.html ) .
ITPERSON 2 Posts Sunday April 19, 2009Registration date April 20, 2009 Last seen - Apr 20, 2009 at 04:18 AM
0
Thank you
Hi All,

i need to ping an IP for ex.. ping 10.10.10.1

and I want to write an if command that if the result give reply then goto another command like goto end

:end
ping host



how can I call the result of the ping in the if command !!!?
0
Thank you
You can use the following script in biterscripting.

# START SCRIPT
var str output ;
system ping "10.10.10.1" > $output
# Did we get any output ?
if ($output <> "")
do
# Yes, we got some output from ping.
# Insert your additional code here.
done
# END SCRIPT

Sen
SenHu 15 Posts Friday May 22, 2009Registration date February 2, 2010 Last seen - Jul 14, 2009 at 11:12 AM
0
Thank you
Reworded quote
i want to rename files a1.txt, a2.txt ...aN.txt files to a1-v1.xt ...aN-vN.txt .


This bitescript will do it. I will assume your files are in folder C:\folder.

# Change dir to C:\folder.
cd "C:\folder"

# Get a list of files a*.txt.
var str list ; lf -n "a*.txt" > $list

# Process files one by one.
while ($list <> "")
do
    # Get the next file in the list.
    var str file ; lex "1" $list > $file

    # Get the sequence number. It is between a and .txt
    var str seq ; stex -p -r -c "^a&\.txt^" $file > $seq ; stex -c "^a^]" $seq > null ; stex -c "[^.txt^" $seq > null

    # New file name is a$seq-v$seq.txt
    var str newname ; set $newname = "a"+$seq+"-v"+$seq+".txt"

    # Rename file
    echo -e "Renaming file " $file " to " $newname
    system rename ("\""+$file+"\"") ("\""+$newname+"\"")
done



Save the script as C:\Scripts\rename.txt. Start biterscripting. Enter the following command.

script rename.txt

That's it. Donwload biterscripting if necessary from http://www.biterscripting.com . It is free. Don't forget to change C:\folder in the script to the correct folder path.

Good luck.

Sen
0
Thank you
Hi,
I want to rename existing about 200 directories (full with data) with new names which are in a .txt file.
Please help me
0
Thank you
Hi,
I want to rename existing about 200 directories (full with data) with new names which are in a .txt file.
Please help me


BUGYXXX:

Can you elaborate on that ? You have 200 directories and you have 200 new names for them in a .txt file. How are the old names and new names to be corelated ? If you have both old and new names in the .txt files, see the solution at http://ccm.net/forum/affich-100607-batch-rename-using-text-file-for-new-name . The system rename command works for both files and folders, so that script should work for directories too. Make sure you have full paths of the old folders in the .txt file.

Sen
0
Thank you
If you are looking for the easy way to batch Rename Files folders by the thousands? RenameMaestro is probably the easiest batch file renamer you'll find to instantly rename multiple files. http://www.ulfwood.net/RenameFiles/FileRenamer.aspx
0
Thank you
Hello,
the code to rename files in a directory is

@echo off
ren ("File path including name") ("File path including new name")
exit
0
Thank you
I want to exit c:\documents and setting\abc in dos command »
I have an answer
& I want to write it
c;\windows\system32>diskpart
0
Thank you
use software called file renamer