Dos script to rename files

Solved/Closed
gbr00435 Posts 1 Registration date Wednesday August 20, 2008 Status Member Last seen August 21, 2008 - Aug 21, 2008 at 11:29 AM
 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

13 replies

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 :))
26
Hey Satya,

Thanks for the dos script to rename files.
I was stuck on that, and had to rename a large directory with 5000 files distributed in several subdirectories.

And your script worked just perfect!!!!

Thanks
AP
0
hi ,

i am trying to use following command for renaming a1.txt, a2.txt ...aN.txt files to a1-v1.xt ...aN-vN.txt
by running
bathc file run
test *.txt *-v1.txt
contents of batch file
For /r %%x in (%1) do ren "%%x" %2

now my files are getting renamed like a1.txt-v1 which I don't want . I want a1-v1.txt
Please can you tell me the dos command for that.

Thanks in advacne
0
Dear all,

I need your help for a bat script.
I have a file called ABC.txt and I want to rename that file to ABC-T.txt
Can anyone help me pls?
Waiting for your answers.




Best regards
0
msk007 > claudiu
Jan 19, 2010 at 07:18 AM
xcopy "C:\ABC.txt" "C:\ABC-T.txt"
0
Hello All,

My system was infected by a virus which has changed the extnesions of all my mp3 songs to jpg.

There are almost 18 GB songs and spread across several folder in a directory. I tried with the script posted above but it didn't worked.

Can anybody help me to change all files with jpg as extension back to mp3

Ram
0
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
2
@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,
1
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 ) .
0

Didn't find the answer you are looking for?

Ask a question
ITPERSON Posts 2 Registration date Sunday April 19, 2009 Status Member Last seen April 20, 2009
Apr 20, 2009 at 04:18 AM
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
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
0
SenHu Posts 15 Registration date Friday May 22, 2009 Status Member Last seen February 2, 2010 14
Jul 14, 2009 at 11:12 AM
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
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
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 https://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
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
Hello,
the code to rename files in a directory is

@echo off
ren ("File path including name") ("File path including new name")
exit
0
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
use software called file renamer
0