Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. DOS question

DOS question

Scheduled Pinned Locked Moved The Lounge
questionhelp
43 Posts 35 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T TheF0rmatter

    For files with numbers less than 10: FOR /L %F in (1,1,9) DO REN L%F.txt L00%F.txt For files with numbers from 10 to 99: FOR /L %F IN (10,1,99) DO REN L%F.txt L0%F.txt You could expand this out with a check to make sure the file exists: FOR /L %F IN (1,1,9 DO IF EXIST L%F.txt REN L%F.txt L00%F.txt

    R Offline
    R Offline
    Russell
    wrote on last edited by
    #31

    that was what I was looking for! thank you -------------------------------------------------------------------- If someone in future will have the same problem I also report here a more complex script I prepared before reading this reply that does the same thing (I hope :~). Because for me it is trivial to not change absolutely the name of the files, then the script is very robust on this feature (and it display a sort of report to check all the progress) Thanks again to all

    @echo off

    @echo File 001 to 009
    set /a cnt1=1
    :DATA0109
    IF NOT EXIST L%cnt1%.sg2 @echo L%cnt1%.sg2 not found
    IF EXIST L%cnt1%.sg2 @echo rename L%cnt1%.sg2 L00%cnt1%.sg2
    IF EXIST L%cnt1%.sg2 rename L%cnt1%.sg2 L00%cnt1%.sg2
    set /a cnt1+=1
    if %cnt1%==10 goto :DATA1099BEGIN
    goto :DATA0109

    :DATA1099BEGIN
    @echo File 010 to 099
    set /a cnt1=0
    set /a cnt2=1
    :DATA1099
    IF NOT EXIST L%cnt2%%cnt1%.sg2 @echo L%cnt2%%cnt1%.sg2 not found
    IF EXIST L%cnt2%%cnt1%.sg2 @echo rename L%cnt2%%cnt1%.sg2 L0%cnt2%%cnt1%.sg2
    IF EXIST L%cnt2%%cnt1%.sg2 rename L%cnt2%%cnt1%.sg2 L0%cnt2%%cnt1%.sg2
    set /a cnt1+=1
    if %cnt1%==10 set /a cnt2+=1
    if %cnt1%==10 set /a cnt1=0
    if %cnt2%==10 goto :EXIT
    goto :DATA1099

    :EXIT
    pause
    goto :EOF


    Russell

    1 Reply Last reply
    0
    • T TheF0rmatter

      For files with numbers less than 10: FOR /L %F in (1,1,9) DO REN L%F.txt L00%F.txt For files with numbers from 10 to 99: FOR /L %F IN (10,1,99) DO REN L%F.txt L0%F.txt You could expand this out with a check to make sure the file exists: FOR /L %F IN (1,1,9 DO IF EXIST L%F.txt REN L%F.txt L00%F.txt

      I Offline
      I Offline
      InfinitelyRemote
      wrote on last edited by
      #32

      Gotta LOVE that FOR-IN-DO!! L_O_
      VE This Suggestion!

      1 Reply Last reply
      0
      • R Rajesh R Subramanian

        +1 for BRU! It works great. :)

        There are some really weird people on this planet - MIM.

        D Offline
        D Offline
        Dale Barnard
        wrote on last edited by
        #33

        BRU has been solid and great for years. You have to upgrade to use it across a network, though.

        1 Reply Last reply
        0
        • H Henry Minute

          I think the best way to do this is to use a batch file and the FOR command. Take a look at this[^] for some ideas.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          E Offline
          E Offline
          edmurphy99
          wrote on last edited by
          #34

          using the old %%n will work for %%n in (\\directory\filename*.txt)

          1 Reply Last reply
          0
          • L Lost User

            Aww, you hurt my feelings. I was just starting to feel special. :) Just kidding - that Total Commander thing does look pretty nice.

            N Offline
            N Offline
            Naruki 0
            wrote on last edited by
            #35

            No offense. I remember when I had to edit huge (for the early 90s) 3MB text files and I used WordPerfect Editor because of all the macro functions. I occasionally wrote little macros for tasks like this to create a batch file. This is about the level of using Excel. It works in a pinch, but... Later I was introduced to both Norton Commander and Sage Professional Editor, and things got even better. SPE was a dream, as it could edit multiple docs at the same time and its macro language used AWK. The consultant who introduced it to us had some nifty tricks to automatically open those text files and jump to the line in the error log. Needless to say I quickly abandoned WP Editor. Then Win95 came out, Norton made one last version of Commander for that platform, SPE changed from a DOS based to a Win95 editor renamed Preditor, and life was looking good. Then Norton Commander was gone, and Preditor was bundled into some insanely overpriced corporate enterprise suite and lost to me forever. I despaired. Eventually I found my first NC clone called Volkov Commander, and it was a decent but slightly buggy thing. Never did find a text editor with an AWK-like macro language. And maybe ten years ago I discovered Windows Commander, subsequently renamed to Total Commander when Microsoft threatened them. It was a superb NC clone, no bugs. And in the years since, he has added features that just make it better and better. Some of them I never used for the longest time, but as I found a need for them I realized just how powerful they are. That file rename feature is one of the incredible ones when you need it. I realize that in Linux this is all done with too clever by half scripts at the command line, but that has never really appealed to me. I like a good GUI. Total Commander makes that stuff easy.

            Narf.

            1 Reply Last reply
            0
            • R Russell

              I have to rename in some folders many file. The file are named like:

              L1.txt
              L2.txt
              ...
              L9.txt
              L10.txt
              ...
              L99.txt
              L100.txt
              ...

              Now, to apply some code, I need that the names changes to

              L001.txt
              ...
              L009.txt
              L010.txt
              ...
              L099.txt
              L100.txt

              I was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like

              rename L?.txt L00?.txt
              rename L??.txt L0??.txt

              but it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)


              Russell

              E Offline
              E Offline
              englebart
              wrote on last edited by
              #36

              Write a program in your favorite language on any platform to generate a throw away batch file. Don't waste too much time messing with all of the DOS quirks. DONT FORGET TO LEAVE ROOM FOR EXPANSION! 110 files today is 100,000 files tomorrow! example in C int i; for (i = 1; i <= 100; ++i) printf("ren L%d.txt L%5.5d.txt\r\n"); capture the output via: a.exe > myrename.bat myrename.bat

              R 1 Reply Last reply
              0
              • R Russell

                I have to rename in some folders many file. The file are named like:

                L1.txt
                L2.txt
                ...
                L9.txt
                L10.txt
                ...
                L99.txt
                L100.txt
                ...

                Now, to apply some code, I need that the names changes to

                L001.txt
                ...
                L009.txt
                L010.txt
                ...
                L099.txt
                L100.txt

                I was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like

                rename L?.txt L00?.txt
                rename L??.txt L0??.txt

                but it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)


                Russell

                N Offline
                N Offline
                Noel Paricollo 2
                wrote on last edited by
                #37

                BetterFileRename: http://www.publicspace.net/windows/BetterFileRename/index.html[^]

                NoelPV2

                1 Reply Last reply
                0
                • R Russell

                  I have to rename in some folders many file. The file are named like:

                  L1.txt
                  L2.txt
                  ...
                  L9.txt
                  L10.txt
                  ...
                  L99.txt
                  L100.txt
                  ...

                  Now, to apply some code, I need that the names changes to

                  L001.txt
                  ...
                  L009.txt
                  L010.txt
                  ...
                  L099.txt
                  L100.txt

                  I was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like

                  rename L?.txt L00?.txt
                  rename L??.txt L0??.txt

                  but it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)


                  Russell

                  D Offline
                  D Offline
                  da808wiz
                  wrote on last edited by
                  #38

                  FYI, I would do it like this (from the command prompt, not from a batch file): for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt that would work to rename the 1-99 files. The 100 file is already in that format. Sincerely G

                  R J 2 Replies Last reply
                  0
                  • D dchuks

                    Use the following script. It does the following: For each *.txt file in the current directory... 1. remove the first character, assuming it is an L 2. add 00 to the front 3. extracts the last 7 characters XXX.txt, where XXX is the original number padded with zeros 4. adds the L back to the front 5. does the rename

                    @echo off
                    setlocal ENABLEDELAYEDEXPANSION
                    for /f "delims=" %%a in ('dir /b *.txt') do (
                    (set i=%%a)
                    (set i=00!i:~1,100!)
                    (set i=L!i:~-7!)
                    echo rename "%%a" to "!i!"
                    rename "%%a" "!i!"
                    )
                    endlocal

                    D Offline
                    D Offline
                    da808wiz
                    wrote on last edited by
                    #39
                    1. okay, now that's the first time I saw the !! being used. I'm not sure in what version that was introduced. 2) I tried it and it only works in a batch file, not from the command prompt, but that's a minor setback, still amazing. 3) I would do it with a slight twist: echo:@echo off>myrename.bat echo:setlocal ENABLEDELAYEDEXPANSION>>myrename.bat echo:for /L %%f in (1,1,100) do (>>myrename.bat echo:(set i=00%%f)>>myrename.bat echo:(set i=!i:~-3!)>>myrename.bat echo:rename L%%f.txt L!i!.txt>>myrename.bat echo:)>>myrename.bat echo:endlocal>>myrename.bat Thanks for the !i! thing...! Sincerely, G
                    1 Reply Last reply
                    0
                    • D da808wiz

                      FYI, I would do it like this (from the command prompt, not from a batch file): for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt that would work to rename the 1-99 files. The 100 file is already in that format. Sincerely G

                      R Offline
                      R Offline
                      Russell
                      wrote on last edited by
                      #40

                      yes, prompt is better then bat. Thats why I was hoping to use something like that rename L?.txt L00?.txt rename L??.txt L0??.txt that was quite understandable and not so difficult to be implemented into the DOS implementation of the command copy, rename, ... :sigh:


                      Russell

                      1 Reply Last reply
                      0
                      • E englebart

                        Write a program in your favorite language on any platform to generate a throw away batch file. Don't waste too much time messing with all of the DOS quirks. DONT FORGET TO LEAVE ROOM FOR EXPANSION! 110 files today is 100,000 files tomorrow! example in C int i; for (i = 1; i <= 100; ++i) printf("ren L%d.txt L%5.5d.txt\r\n"); capture the output via: a.exe > myrename.bat myrename.bat

                        R Offline
                        R Offline
                        Russell
                        wrote on last edited by
                        #41

                        :laugh: yes...nice tip


                        Russell

                        1 Reply Last reply
                        0
                        • D da808wiz

                          FYI, I would do it like this (from the command prompt, not from a batch file): for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt that would work to rename the 1-99 files. The 100 file is already in that format. Sincerely G

                          J Offline
                          J Offline
                          jsc42
                          wrote on last edited by
                          #42

                          The code

                          NuLiFree wrote:

                          for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt

                          does not cater for missing entries. You could add 2>nul to the end of the renames to hide the errors, but the following (untested) would be safer and (in the second set) faster if some cases are not required:

                          for %f in (1 2 3 4 5 6 7 8 9) do if exist L%f.txt rename L%f.txt L00%f.txt
                          for %f in (1 2 3 4 5 6 7 8 9) do if exist L%f?.txt for %g in (0 1 2 3 4 5 6 7 8 9) do if exist L%f%g.txt rename L%f%g.txt L0%f%g.txt

                          You might want to change the two occurrences of (1 2 3 4 5 6 7 8 9) to (0 1 2 3 4 5 6 7 8 9) to catch some erroneously named files.

                          1 Reply Last reply
                          0
                          • B Bassam Abdul Baki

                            Best tool ever.[^]

                            B Offline
                            B Offline
                            blue lizard
                            wrote on last edited by
                            #43

                            I've used this before and I totally agree.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups