Computing.Net > Forums > Programming > Ren multiple files in DOS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ren multiple files in DOS

Reply to Message Icon

Name: mac99
Date: June 3, 2009 at 04:23:56 Pacific
OS: Windows XP
CPU/Ram: 1GB
Product: Dell / GX280
Subcategory: Batch
Comment:

Any help would be appreciated.
I need to rename multiple files in a folder (to insert 4set characters at the beginning of the filename and move the numbers to the end of the file name) where the filename is typically an address (ie 27,Mystreet.doc) to read ABC_Mystreet,27.doc preferably via a DOS batch file? Any ideas?Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 3, 2009 at 19:23:59 Pacific
Reply:

is ABC a constant? show real life examples of your file naming conventions and show more examples of your renamed file names.


0

Response Number 2
Name: mac99
Date: June 3, 2009 at 23:46:44 Pacific
Reply:

Thanks for responding.Yes, ABC is a constant(actually its ASB_ ). The files are normally .doc or .pdf and the convention is nn streetname (ie 02 thomas street or 5 acorn road) - in a number of cases the filename also has COMPLETE as the final part of the filename ( 02 thomas street COMPLETE). The renamed file should read ASB_thomas street,02 or ASB_acorn road,2 (the COMPLETE is to be deleted in all cases)
Thanks again.


0

Response Number 3
Name: ghostdog
Date: June 4, 2009 at 00:09:39 Pacific
Reply:

if you have Python on Windows

import os
path=os.path.join("c:\\","test")
os.chdir(path)
for files in os.listdir(path):
    ext = files[-4:]
    name=files[:-4]
    if ext == ".doc" or ext == ".pdf":
        files=files.replace("COMPLETE","")
        number,street = name.split(" ",1)
        newfilename = "ASB_"+street+","+number+ext
        os.rename(files,newfilename)


save the above as myscript.py and on command line
C:\test>dir /B *.pdf *.doc
02 thomas street.pdf
5 acorn road.doc

C:\test>python test.py

C:\test>dir /B *.pdf *.doc
ASB_thomas street,02.pdf
ASB_acorn road,5.doc



0

Response Number 4
Name: mac99
Date: June 4, 2009 at 02:54:42 Pacific
Reply:

Sorry but i don't have Python (& our techies have locked down the pc's for software downloads!)
Is there an alternative solution using MSDOS Command prompt (WinXP)? (the python script does look the biz tho!)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Ren multiple files in DOS

display Tiff file in DOS/C/TSR www.computing.net/answers/programming/display-tiff-file-in-dosctsr/2195.html

Replacing file in Dos www.computing.net/answers/programming/replacing-file-in-dos/17225.html

Help needed renaming a file in DOS www.computing.net/answers/programming/help-needed-renaming-a-file-in-dos/12770.html