Renaming files in DOS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ymk
    New Member
    • Nov 2006
    • 24

    Renaming files in DOS

    Hello,

    I need to rename files in a folder. I was trying to use DOS ( "ren" ) but was unsuccessful.

    Can someone give me a hint how this can be done.

    I want the First 3 Chars to be removed from Original file name.

    Original FileName: ABC12345.txt, ABC88898.txt, ABC67890.txt

    Desired FileName: 12345.txt, 88898.txt, 67890.txt

    Thanks,
    K
  • Stang02GT
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    what operating system, are you using?

    Cause you can just right click on the file in windows and there should be a "rename" option you can select. Then just edit the file name, unless you absolutely have to you don't need to do this in dos.

    Comment

    • Stang02GT
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #3
      But if you would like to do it in DOS, here is a link to a site that i think we be helpful to you...


      Comment

      • ymk
        New Member
        • Nov 2006
        • 24

        #4
        This is in Windows 2000 Pro.

        I need some thing like a batch file to do this as there are 100's of files.

        I need rename using the wild cards like ( *, ? ). I tried using them but didnt get the desired result.

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by ymk
          Hello,

          I need to rename files in a folder. I was trying to use DOS ( "ren" ) but was unsuccessful.

          Can someone give me a hint how this can be done.

          I want the First 3 Chars to be removed from Original file name.

          Original FileName: ABC12345.txt, ABC88898.txt, ABC67890.txt

          Desired FileName: 12345.txt, 88898.txt, 67890.txt

          Thanks,
          K
          If the number part is always 5 digit, and total length is 8, then use this...

          ren *?????.* ?????.*

          Comment

          • ymk
            New Member
            • Nov 2006
            • 24

            #6
            Originally posted by hsriat
            If the number part is always 5 digit, and total length is 8, then use this...

            ren *?????.* ?????.*

            hsriat,

            I tried the same as you suggested but somehow its retaining the first chars than the latter.

            ex: for ABC12345.txt, its renaming it as ABC12.txt.

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by ymk
              hsriat,

              I tried the same as you suggested but somehow its retaining the first chars than the latter.

              ex: for ABC12345.txt, its renaming it as ABC12.txt.

              Yeah, I checked that. It retains the first five.

              It's better for you if you consult the C++ guys. They would probably know thae C++ way of renaming.

              Comment

              • ymk
                New Member
                • Nov 2006
                • 24

                #8
                Originally posted by hsriat
                Yeah, I checked that. It retains the first five.

                It's better for you if you consult the C++ guys. They would probably know thae C++ way of renaming.
                Thanks hsriat. I am a C++ programmer myself. I thought I could do it in DOS easily but think I have no choice else to write a program.

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  Originally posted by ymk
                  Thanks hsriat. I am a C++ programmer myself. I thought I could do it in DOS easily but think I have no choice else to write a program.
                  I tried a lot after you said that my previous solution didn't work. Altho I was somewhat good in DOS 10 years ago, I couldn't provide you with a solution. So I suggested you that.

                  :)

                  Comment

                  • MedIt
                    New Member
                    • Feb 2008
                    • 15

                    #10
                    Originally posted by hsriat
                    I tried a lot after you said that my previous solution didn't work. Altho I was somewhat good in DOS 10 years ago, I couldn't provide you with a solution. So I suggested you that.

                    :)
                    Hi,
                    not sure if you have solved this problem, but I have a solution to rename it in batch file!

                    Assuming that you want to strip off the first 3 characters of your filename:
                    In your for loop you can do something like:

                    for /f "usebackq" %%i in (`dir /b /on`) do call :COPY %%i
                    goto :EOF

                    :COPY
                    echo %1
                    set filename=%1
                    rem stripping off the first 3 chars
                    set newF=%filename: ~3%
                    copy %1 %newF%
                    goto :EOF

                    This obviously you are using the copy to do the trick, you can get rid of the old(original) file as you rename it to an archive folder.
                    This should work!

                    Comment

                    Working...