CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Posts
    33

    Renaming multiple files in DOS

    Hi All,
    I am in a situation like this:
    I have close to 100 files ordered like this:
    test1.txt
    test2.txt
    test3.txt
    ...
    ...
    test99.txt

    I need to rename those files like this:
    track1.txt
    track2.txt
    ...
    ...
    track99.txt
    i.e. trackNN.txt

    Of course, with windows, I can rename them whatever I like one by one.

    But with commad prompt (DOS command) how do I do that?

    ren test*.txt track*.txt did not work
    I want to change the alphabet part, leaving the numerals intact.

    Is it possible?

    Thank you for your time.

    Best,
    T.

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: Renaming multiple files in DOS

    There is no easy way to do this in a ".bat" file.
    Instead you could do this in VBS (VBS is the scripting language supposed to replace old DOS commands, and is available since Windows 95).
    Or, better, use a good third party tool, e.g. ant renamer. See http://www.antp.be/software/renamer

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Renaming multiple files in DOS

    Pretty sure you can use a SINGLE-CHARACTER WILDCARD. Not sure if it's & or _

    Code:
    ren t&&&*.txt track*.txt
    Otherwise, look into POWERSHELL. It can do that
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2004
    Posts
    33

    Re: Renaming multiple files in DOS

    Hi olivthill2, dglienna,
    Thank you for your answers.

    ren t&&&*.txt track*.txt and ren t___*.txt track*.txt did not work.

    I will have to use some other ways. Let's see if I can use powershell- never used this before.
    T

  5. #5
    Join Date
    Jan 2010
    Posts
    14

    Re: Renaming multiple files in DOS

    I don't know if this works on all windows computers, but on windows vista if you select all the files you want to rename, then press F2, it'll allow you to rename a file and then it will take that same name and name all the files selected under that name and number them. Pretty easy and convenient alternative.

  6. #6
    Join Date
    Jul 2004
    Posts
    33

    Re: Renaming multiple files in DOS

    Hi,
    Yes, even in my XP, it works. I mean it renames files like track (1).txt, track (2).txt, etc.
    Unfortunately, for my purpose, that was not useful.
    The end device that uses the files (track1.txt, track2.txt.....) could not read track (1).txt, track (2).txt, etc.
    Thanks.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Renaming multiple files in DOS

    Once again, try VBSCRIPT

    Code:
    Const ForReading = 1
    
    strComputer = "."
    set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("c:\scripts\names.txt", ForReading)
    
    Do Until objFile.AtEndOfStream
        strLine = objFile.ReadLine
        arrParts = Split(strLine, ",")
        strFile = "C:\\Pictures\\" & arrParts(0)
        Set colItems  = objWMIService.ExecQuery _
            ("Select * From CIM_Datafile Where Name = '" & strFile & "'")
        For Each objItem in colItems
            strNewName = "C:\Pictures\" & arrParts(1)
            objItem.Rename strNewName
        Next
    Loop
    
    objFile.Close
    http://blogs.technet.com/heyscriptin...text-file.aspx
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jul 2004
    Posts
    33

    Re: Renaming multiple files in DOS

    Hi dglienna,
    Thanks for the post.

  9. #9
    Join Date
    Feb 2010
    Posts
    3

    Re: Renaming multiple files in DOS

    If you install Cygwin, the following will work in the Cygwin prompt:
    Code:
    cd "/cygdrive/c/Documents and Settings/whatever folder/the files are in/"
    for i in `ls` ; do mv $i `echo $i | sed "test/track/"`; done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured