Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: help with a .bat file  (Read 10055 times)

0 Members and 1 Guest are viewing this topic.

xfusion

    Topic Starter


    Rookie

    Re: help with a .bat file
    « Reply #15 on: December 09, 2009, 04:08:57 PM »
    thanks a lot i really appreciate the steering in the correct direction, i think if i only do the
    "dir > mytext.txt" it will give me all the information i need, since there will never be any sub-sub directories and i only need the list of the directories in the main folder, so i will give that a try, that coupled with the for command should give me the enter directory, run "ren *_std *_std.mpg" exit go to next directory, as for the adding 0, all of the the files will ALWAYS be named "2-, 3-, 4-, 5-, 6-, 7-, 8-, 9-, 10-, 11-, ect.." the - always followed by random letters and only the 2-9 need the zero added to it (to make them alphabetical in the folder)

    i attached a few pictures to help visually display what needs to be done (a before and after) and a overview of the main folder (where it will be run)

    as for the vbs i'm not exactly sure on how to run it, i saved the one part as vbs and got stuck, i haven't had time to look further into it, and yes it can be a vbs, it can be anything honestly as long as the job gets done  :P

    i will work on making the .bat and see how it goes  ;D

    [Saving space, attachment deleted by admin]

    xfusion

      Topic Starter


      Rookie

      Re: help with a .bat file
      « Reply #16 on: December 09, 2009, 04:10:16 PM »
      btw in the after picture, the little purple/orange.. things are media files, means they have been renamed .mpg

      The_Game_Bane



        Rookie

        Re: help with a .bat file
        « Reply #17 on: December 11, 2009, 09:21:48 AM »
        i think i cud solve the 1st query

        FOR /R %%i in (*_std) do ren *_std.mpg %%i

        Salmon Trout

        • Guest
        Re: help with a .bat file
        « Reply #18 on: December 11, 2009, 09:29:43 AM »
        i think i cud solve the 1st query

        FOR /R %%i in (*_std) do ren *_std.mpg %%i

        I think you got that backwards

        xfusion

          Topic Starter


          Rookie

          Re: help with a .bat file
          « Reply #19 on: December 11, 2009, 11:55:41 AM »
          i have the renaming and the adding 0 done

          ren *_std *_std.mpg
          ren 2-* 02-*
          ren 3-* 03-*
          ren 4-* 04-*
          ren 5-* 05-*
          ren 6-* 06-*
          ren 7-* 07-*
          ren 8-* 08-*
          ren 9-* 09-*


          that works perfectly, all i need now is for it to go into every directory in a folder and run that so i only have to run it once instead of 15-20 times, once in each folder

          billrich



            Rookie

            Thanked: 1
            Re: help with a .bat file
            « Reply #20 on: December 11, 2009, 03:55:47 PM »
            Sounds great.

            List all your code plus  the input and the output.

            The code will help many people.

            Thanks for your help.

            ghostdog74



              Specialist

              Thanked: 27
              Re: help with a .bat file
              « Reply #21 on: December 11, 2009, 05:57:46 PM »
              as for the vbs i'm not exactly sure on how to run it, i saved the one part as vbs and got stuck, i haven't had time to look further into it, and yes it can be a vbs, it can be anything honestly as long as the job gets done  :P
              got stuck? how? what errors you got? did you change working folder to c:\test? I done the script in c:\test, so you should change to appropriate path at your side where you want to rename your files.

              ghostdog74



                Specialist

                Thanked: 27
                Re: help with a .bat file
                « Reply #22 on: December 11, 2009, 05:59:30 PM »
                Sounds great.

                List all your code plus  the input and the output.

                The code will help many people.

                Thanks for your help.


                did you see reply #19 ?? that's all he has at the moment. 9 rename commands, which i think he can just use a for loop.

                Salmon Trout

                • Guest
                Re: help with a .bat file
                « Reply #23 on: December 12, 2009, 04:09:48 AM »
                assuming the subfolders are all directly below a root folder

                that is, in the top folder dir /ad shows something like this

                Code: [Select]
                12/12/2009  11:00    <DIR>          .
                12/12/2009  11:00    <DIR>          ..
                12/12/2009  11:00    <DIR>          Subfolder1
                12/12/2009  11:00    <DIR>          Subfolder2
                12/12/2009  11:00    <DIR>          Subfolder3
                12/12/2009  11:00    <DIR>          Subfolder4
                12/12/2009  11:00    <DIR>          Subfolder5
                12/12/2009  11:00    <DIR>          Subfolder6
                12/12/2009  11:00    <DIR>          Subfolder7
                12/12/2009  11:00    <DIR>          Subfolder8

                note... for testing purposes the subfolders have identical contents thus

                Code: [Select]
                2-apniia_std
                3-apniqe_std
                4-apniyi_std
                5-apnjgm_std
                6-apnjoq_std
                7-apnjwu_std
                8-apnkey_std
                9-apnknc_std

                Code: [Select]
                @echo off

                set thisdir=%cd%

                Echo Scanning subfolders

                for /f "delims=" %%D in ('dir /b /ad') do (
                       
                        echo Entering subfolder: %%D
                       
                        cd /d "%%D"
                        Echo Renaming *_std to *_std.mpg
                       
                        if exist *_std (
                               
                                for /f "delims=" %%S in ('dir /b *_std') do (
                               
                                        echo Renaming %%S to %%S.mpg
                                       
                                        ren "%%S" "%%S.mpg"
                               
                                )
                               
                        ) else (
                       
                                echo *_std : no files to process
                       
                        )
                       
                       
                        Echo Renaming 2-* to 9-* to 02-* to 09-*
                        for %%N in (2 3 4 5 6 7 8 9) do (
                               
                                if exist "%%N-*" (
                                       
                                        for /f "delims=" %%F in ('dir /b %%N-*') do (
                                       
                                                echo Renaming %%F to 0%%F
                                               
                                                ren "%%F" "0%%F"
                                       
                                        )
                               
                                ) else (
                               
                                        echo %%N-* :   no files to process
                               
                                )
                       
                        )
                       
                        cd /d %thisdir%

                )   

                pause
                     
                     

                Code: [Select]
                Scanning subfolders
                Entering subfolder: Subfolder1
                Renaming 3-apniqe_std to 3-apniqe_std.mpg
                Renaming 4-apniyi_std to 4-apniyi_std.mpg
                Renaming 5-apnjgm_std to 5-apnjgm_std.mpg
                Renaming 6-apnjoq_std to 6-apnjoq_std.mpg
                Renaming 7-apnjwu_std to 7-apnjwu_std.mpg
                Renaming 8-apnkey_std to 8-apnkey_std.mpg
                Renaming 9-apnknc_std to 9-apnknc_std.mpg
                Renaming 2-apniia_std to 2-apniia_std.mpg
                Renaming 2-apniia_std.mpg to 02-apniia_std.mpg
                Renaming 3-apniqe_std.mpg to 03-apniqe_std.mpg
                Renaming 4-apniyi_std.mpg to 04-apniyi_std.mpg
                Renaming 5-apnjgm_std.mpg to 05-apnjgm_std.mpg
                Renaming 6-apnjoq_std.mpg to 06-apnjoq_std.mpg
                Renaming 7-apnjwu_std.mpg to 07-apnjwu_std.mpg
                Renaming 8-apnkey_std.mpg to 08-apnkey_std.mpg
                Renaming 9-apnknc_std.mpg to 09-apnknc_std.mpg

                Entering subfolder: Subfolder2
                Renaming 3-apniqe_std to 3-apniqe_std.mpg
                Renaming 4-apniyi_std to 4-apniyi_std.mpg
                Renaming 5-apnjgm_std to 5-apnjgm_std.mpg
                Renaming 6-apnjoq_std to 6-apnjoq_std.mpg
                Renaming 7-apnjwu_std to 7-apnjwu_std.mpg
                Renaming 8-apnkey_std to 8-apnkey_std.mpg
                Renaming 9-apnknc_std to 9-apnknc_std.mpg
                Renaming 2-apniia_std to 2-apniia_std.mpg
                Renaming 2-apniia_std.mpg to 02-apniia_std.mpg
                Renaming 3-apniqe_std.mpg to 03-apniqe_std.mpg
                Renaming 4-apniyi_std.mpg to 04-apniyi_std.mpg
                Renaming 5-apnjgm_std.mpg to 05-apnjgm_std.mpg
                Renaming 6-apnjoq_std.mpg to 06-apnjoq_std.mpg
                Renaming 7-apnjwu_std.mpg to 07-apnjwu_std.mpg
                Renaming 8-apnkey_std.mpg to 08-apnkey_std.mpg
                Renaming 9-apnknc_std.mpg to 09-apnknc_std.mpg

                Entering subfolder: Subfolder3

                [etc]


                Subfolder contents after run

                Code: [Select]
                02-apniia_std.mpg
                03-apniqe_std.mpg
                04-apniyi_std.mpg
                05-apnjgm_std.mpg
                06-apnjoq_std.mpg
                07-apnjwu_std.mpg
                08-apnkey_std.mpg
                09-apnknc_std.mpg

                Of course the same code could be written in a much more compact form, but for (hopefully) instructive purposes I have used plenty of echo statements, multilining and indenting to make the flow of control easier to grasp (I hope). I have got into the habit of using "if exist" tests before file operations because I don't like error messages cluttering up the console.
                « Last Edit: December 12, 2009, 04:41:25 AM by Salmon Trout »

                ghostdog74



                  Specialist

                  Thanked: 27
                  Re: help with a .bat file
                  « Reply #24 on: December 12, 2009, 04:37:16 AM »
                  how about this, since we only have 2-9 (or is it 1-9?)
                  Code: [Select]
                  ...
                         for /f "delims=" %%F in ('dir /b 2-* 3-* 4-* 5-* 6-* 7-* 8-* -9-*') do (
                                 echo Renaming %%F to 0%%F
                         )
                  ...
                  you reduce 1 extra for loop that calls dir 8 more times. Also, why is it you don't use /s for dir? like dir /b /s *-*std ?

                  Salmon Trout

                  • Guest
                  Re: help with a .bat file
                  « Reply #25 on: December 12, 2009, 05:11:20 AM »
                  how about this, since we only have 2-9 (or is it 1-9?)
                  Code: [Select]
                  ...
                         for /f "delims=" %%F in ('dir /b 2-* 3-* 4-* 5-* 6-* 7-* 8-* -9-*') do (
                                 echo Renaming %%F to 0%%F
                         )
                  ...
                  you reduce 1 extra for loop that calls dir 8 more times. Also, why is it you don't use /s for dir? like dir /b /s *-*std ?

                  Well, to tell the truth I had forgotten that you can have multiple wild cards in one dir statement like this

                  dir /b 2-* 3-* 4-* 5-* 6-* 7-* 8-* -9-*

                  but even if I had remembered I would have done it the other way because (stepping back from the purely 'writing code' perspective) it seems more orderly to process each number separately, and similarly for the dir /b /s *-*std question. Processing all the sub folders down to all levels may not be what the OP wants. Sometimes (I feel) the pursuit of code that looks good in the editor can obscure other advantages. Processing power is cheap but clarity of thought and its expression are valuable things.






                  ghostdog74



                    Specialist

                    Thanked: 27
                    Re: help with a .bat file
                    « Reply #26 on: December 12, 2009, 05:24:44 AM »
                    Processing power is cheap but clarity of thought and its expression are valuable things.
                    true, that's why i never program in batch :)

                    Salmon Trout

                    • Guest
                    Re: help with a .bat file
                    « Reply #27 on: December 12, 2009, 05:35:13 AM »
                    I think that programming scripting in batch is a useful ability, but I do not think it is an essential one. However, there is much that can be done with it.

                    xfusion

                      Topic Starter


                      Rookie

                      Re: help with a .bat file
                      « Reply #28 on: December 14, 2009, 12:13:23 PM »
                      only ran into one issue with the program you put salmon, it renames the _std.idx files _std.mpg.idx so i changed it to

                      Code: [Select]
                      if exist *_std (
                                     
                      if *_std.idx(
                      echo idx file
                      )
                      else
                      (
                                      for /f "delims=" %%S in ('dir /b *_std') do (
                                     
                                              echo Renaming %%S to %%S.mpg
                                             
                                              ren "%%S" "%%S.mpg"
                              )       
                                      )
                                     
                              ) else (
                             
                                      echo *_std : no files to process
                             
                              )

                      that should work correct?

                      xfusion

                        Topic Starter


                        Rookie

                        Re: help with a .bat file
                        « Reply #29 on: December 14, 2009, 12:48:20 PM »
                        then again, wouldn't this work?

                        Code: [Select]
                        @echo off

                        set thisdir=%cd%

                        Echo Scanning subfolders

                        for /f "delims=" %%D in ('dir /b /ad') do (
                               
                                echo Entering subfolder: %%D
                               
                                cd /d "%%D"
                                Echo Renaming *_std to *_std.mpg
                        ren *_std *_std.mpg
                        Echo renaming 2 to 02
                        ren 2-* 02-*
                        ren 3-* 03-*
                        ren 4-* 04-*
                        ren 5-* 05-*
                        ren 6-* 06-*
                        ren 7-* 07-*
                        ren 8-* 08-*
                        ren 9-* 09-*

                               
                                cd /d %thisdir%

                        )   

                        pause

                        less informative