CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • ADO.NET Data Services in the .NET Framework
  • Visual C++ Programming: What's new for MFC library in VC++ 2010?
  • Microsoft Visual Studio LightSwitch and What It Can Do For You
  • Displaying Files and Folders in a GridView

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > General Discussion > General Discussion / Chit Chat
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    General Discussion / Chit Chat Free form discussion forum to discuss issues that do not belong in any of the other boards. NOTE: Posts in this forum do not count towards totals.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 10th, 2010, 01:34 AM
    Tienshan Tienshan is offline
    Member
     
    Join Date: Jul 2004
    Posts: 33
    Tienshan is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #2    
    Old February 10th, 2010, 08:34 AM
    olivthill2 olivthill2 is offline
    Member
     
    Join Date: Apr 2009
    Posts: 457
    olivthill2  is a jewel in the rough (300+)olivthill2  is a jewel in the rough (300+)olivthill2  is a jewel in the rough (300+)olivthill2  is a jewel in the rough (300+)
    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
    Reply With Quote
      #3    
    Old February 10th, 2010, 06:22 PM
    dglienna's Avatar
    dglienna dglienna is offline
    ex MVP - Visual Basic
    Power Poster
     
    Join Date: Jan 2006
    Location: Chicago, IL
    Posts: 11,445
    dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)
    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
    101 Samples: VB & C# VS2008 Samples & VS2010 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!
    Reply With Quote
      #4    
    Old February 11th, 2010, 08:17 PM
    Tienshan Tienshan is offline
    Member
     
    Join Date: Jul 2004
    Posts: 33
    Tienshan is an unknown quantity at this point (<10)
    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
    Reply With Quote
      #5    
    Old February 11th, 2010, 08:43 PM
    thisismyusername2010 thisismyusername2010 is offline
    Junior Member
     
    Join Date: Jan 2010
    Posts: 13
    thisismyusername2010 is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #6    
    Old February 11th, 2010, 11:54 PM
    Tienshan Tienshan is offline
    Member
     
    Join Date: Jul 2004
    Posts: 33
    Tienshan is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #7    
    Old February 12th, 2010, 07:00 PM
    dglienna's Avatar
    dglienna dglienna is offline
    ex MVP - Visual Basic
    Power Poster
     
    Join Date: Jan 2006
    Location: Chicago, IL
    Posts: 11,445
    dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)dglienna has a reputation beyond repute (3000+)
    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
    101 Samples: VB & C# VS2008 Samples & VS2010 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!
    Reply With Quote
      #8    
    Old February 14th, 2010, 11:44 AM
    Tienshan Tienshan is offline
    Member
     
    Join Date: Jul 2004
    Posts: 33
    Tienshan is an unknown quantity at this point (<10)
    Re: Renaming multiple files in DOS

    Hi dglienna,
    Thanks for the post.
    Reply With Quote
      #9    
    Old February 14th, 2010, 02:46 PM
    maxtothemax maxtothemax is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 3
    maxtothemax is an unknown quantity at this point (<10)
    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
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > General Discussion > General Discussion / Chit Chat


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:07 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.