Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MS-DOS question, how to rename files from DOS?

Status
Not open for further replies.

ahmad_abdulghany

Advanced Member level 4
Advanced Member level 4
Joined
Apr 12, 2005
Messages
1,206
Helped
102
Reputation
206
Reaction score
22
Trophy points
1,318
Location
San Jose, California, USA
Activity points
11,769
Hello all,

I have a group of files have similar names, that is: 1001.mp3, 1002.mp3, ..., 1xxx.mp3 .. where xxx is only integers...

Now, can I using the MS-DOS command line, rename them all, from 1xxx.mp3 into xxx.mp3 only? How?

And, how can this be also done using Linux terminal?

i can make it easily using Matlab function movefile() together with loops, and i know that it will be done in similar manner in DOS or Linux Shell using move and mv functions, but how to do it with group of files not only one file??

Thanks in advance,
Ahmad,
 

It can be easily done using BASH script in Linux.
 

in ms-DOS
the command is REN
example
REN 1001.txt 001.txt

you can also do it my total commander
very quickly
 

This ugly mess works from the Win2k command prompt:
for /L %a in (0,1,9) do for /L %b in (0,1,9) do for /L %c in (0,1,9) do ren 1%a%b%c.mp3 %a%b%c.mp3 2> nul

It runs faster in a batch file. Remember to set "echo off" and replace % with %%

To run it in DOS 6.22, try omitting the /L and replacing (0,1,9) with (0,1,2,3,4,5,6,7,8,9). I don't know how to redirect stderr in DOS (to hide the "file not found" messages), so you may also need to eliminate the "2> nul".

Yuch!
 
Thank you echo47, you understood what i want..

I'm now at work, and i don't have Windows to test on DOS here, when i go to home at evening i will try it, and reply agan,

xxtigerxx, I know that it can be done using either ren or move commands on DOS, but this valid for single file, but what i am speaking for is large number of fiiles (group of files)

adsl, what should that bash script contain? commands.

Thank you all for your help,
and i hope to get more replies,

Regards,
Ahmad,
 

Here's a totally different approach, one that I use frequently at the Windows/DOS command line:

First I create a batch file containing a long list of all the filenames:
dir /b 1???.mp3 > foo.bat

Then I edit the batch file with my favorite text editor. I use a fancy macro search-and-replace to change all the individual filenames into rename commands.

Then I run the batch file.
 

echo47 said:
Here's a totally different approach, one that I use frequently at the Windows/DOS command line:

First I create a batch file containing a long list of all the filenames:
dir /b 1???.mp3 > foo.bat

Then I edit the batch file with my favorite text editor. I use a fancy macro search-and-replace to change all the individual filenames into rename commands.

Then I run the batch file.

What do you mean by the fancy macro search-and-replace? :)

And what that powerfull (!!) text editor you use under Windows? Emacs :D ?

I hope i can do so, you told me before how to do it in Matlab, do you remember? :) (look at it **broken link removed** if you are interested)

but how in Windows XP DOS now?

Please, explain in some details, what will you do to edit the batch file into rename commands..

Thanks alot in dvance
Ahmad,
 
Last edited by a moderator:

My favorite program/text editor is an obscure DOS app called TSE, The SemWare Editor. Long ago it was called QEdit. Highly configurable. It has keyboard macros and can do Unix-like regular-expression search-and-replace. That's what I meant by "fancy".
https://www.semware.com/

But you probably don't want that old beast! A good popular Windows program/text editor is UltraEdit. However, I have very little experience with this nice tool.
https://www.ultraedit.com/

Another option would be to edit the list of filenames with 'sed', the unix stream editor. You can find a Windows version somewhere. It runs from the command line, and performs a regular-expression search-and-replace on each input line (each filename). Something like this gibberish:
dir /b 1???.mp3 | sed -e "s/1\(...\).mp3/ren 1\1.mp3 \1.mp3/" > foo.bat
 
I wonder, do you write Perl script?
I was going to learn Perl these days!
I think that the term: "Regular-expression" is got from Perl, isn't it?

anyway, if you are using it, will it be helpfull to me in similar issues to mine here?
and will it need any extra things to be installed if i will run under windows?

Thanks,
Ahmad,
 

ahmad_abdulghany said:
I wonder, do you write Perl script?
I was going to learn Perl these days!
I think that the term: "Regular-expression" is got from Perl, isn't it?

anyway, if you are using it, will it be helpfull to me in similar issues to mine here?
and will it need any extra things to be installed if i will run under windows?

Thanks,
Ahmad,

to get perl, just download and install
**broken link removed**
programming is same, but most of perl scripts are targeted for *NIX
using *NIX cmds in `` (backqoutes) or sytem().


before Perl, Regexp concept was there but Perl regexp support is best. (infact other says, their Regexp implementation is Perl-Compatible!)
 
Last edited by a moderator:

In Linux, there is a tool called rename can do such a task:
rename 's/^1//' *.mp3
If rename is not installed, a for command in bash is also enough:
Code:
for file in 1*.mp3; do mv $file ${file#?}; done
 
I have another case..
I want to renam a batch of files from names: s1, s2, s3, .... s10, s11, s12, ....s100, s101, ....s114 to 001, 002, 003, ....114

How can it be done on DOS as first echo47's reply??

Thanks,
Ahmad,
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top