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

Author Topic: Batch not quite working right????  (Read 9183 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Batch not quite working right????
« Reply #15 on: April 09, 2015, 02:06:20 PM »
I am interested to see how you solve this.

nameci

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows 7
    Re: Batch not quite working right????
    « Reply #16 on: April 09, 2015, 02:07:51 PM »
    I will let you know as soon as I do  :)

    nameci

      Topic Starter


      Rookie

      • Experience: Familiar
      • OS: Windows 7
      Re: Batch not quite working right????
      « Reply #17 on: April 10, 2015, 07:15:59 AM »
      Hi Salmon Trout,

      Thanks for all of your help, here is the solution to the problem  ;D


      @echo off
      setlocal enableDelayedExpansion
      cd /d C:\Users\jbrown\Desktop\Test
      set I=2
      :NextI
      if /I %I% LEQ 999 set II=0%I%
      if /I %I% LEQ 99 set II=00%I%
      if /I %I% LEQ 9 set II=000%I%
      if not exist "15-P!II!*" (       
          set /p "client_name=OPTIONAL Enter a client name and press <ENTER>:  "


          xcopy /s /e /i "15-P0000-Template" "15-P!II!!client_name!"

          goto :eof

      )
      set /a I+=1

      if /i %I% LSS 999 goto NextI


      ADDED THE ASTERISK

      Salmon Trout

      • Guest
      Re: Batch not quite working right????
      « Reply #18 on: April 10, 2015, 09:51:49 AM »
      And what problem does the asterisk solve?

      nameci

        Topic Starter


        Rookie

        • Experience: Familiar
        • OS: Windows 7
        Re: Batch not quite working right????
        « Reply #19 on: April 10, 2015, 09:54:54 AM »
        It bypasses the: set I=2 and recognizes the last number used each time the batch is run ;D

        Salmon Trout

        • Guest
        Re: Batch not quite working right????
        « Reply #20 on: April 10, 2015, 09:58:58 AM »
        It bypasses the: set I=2 and recognizes the last number used each time the batch is run ;D

        Are you sure?

        nameci

          Topic Starter


          Rookie

          • Experience: Familiar
          • OS: Windows 7
          Re: Batch not quite working right????
          « Reply #21 on: April 10, 2015, 10:17:18 AM »
          Yup, it works perfectly now.  What are your thoughts?

          Salmon Trout

          • Guest
          Re: Batch not quite working right????
          « Reply #22 on: April 10, 2015, 10:32:24 AM »
          Yup, it works perfectly now.  What are your thoughts?
          Well done!

          nameci

            Topic Starter


            Rookie

            • Experience: Familiar
            • OS: Windows 7
            Re: Batch not quite working right????
            « Reply #23 on: April 10, 2015, 10:37:51 AM »
            Thanks again for all of your help  ;D

            Squashman



              Specialist
            • Thanked: 134
            • Experience: Experienced
            • OS: Other
            Re: Batch not quite working right????
            « Reply #24 on: April 10, 2015, 12:51:31 PM »
            I am more baffled as to why you are using the CASE INSENSITIVE switch with your IF command and you also do not need delayed expansion for the II variable.

            And easier way to zero fill a number.
            Code: [Select]
            set II=000000000%I%
            set II=%II:~-3%

            Salmon Trout

            • Guest
            Re: Batch not quite working right????
            « Reply #25 on: April 10, 2015, 12:54:46 PM »
            And easier way to zero fill a number

            Yes, definitely, and you can use different pad characters e.g. spaces if you want to make neat tables

            nameci

              Topic Starter


              Rookie

              • Experience: Familiar
              • OS: Windows 7
              Re: Batch not quite working right????
              « Reply #26 on: April 10, 2015, 12:56:29 PM »
              I just started learning batch a few weeks ago.  So I started by looking at some examples here and there of existing batch files.  Your advice on how to do things better and easier is greatly appreciated.  :)

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: Batch not quite working right????
              « Reply #27 on: April 10, 2015, 01:00:21 PM »
              I just started learning batch a few weeks ago.  So I started by looking at some examples here and there of existing batch files.  Your advice on how to do things better and easier is greatly appreciated.  :)
              Since you are Zero filling your file names, they will basically always sort in perfect alpha numeric sequence in a batch file.  You could use a FOR command to get the file with the largest number and then strip the leading zeros and add 1 to it instead of incrementing a variable and checking if it doesn't exist.  If you get up to hundreds of files your code will be extremely slow.

              Salmon Trout

              • Guest
              Re: Batch not quite working right????
              « Reply #28 on: April 10, 2015, 01:02:48 PM »
              Personally, I would store the next number in a file.

              nameci

                Topic Starter


                Rookie

                • Experience: Familiar
                • OS: Windows 7
                Re: Batch not quite working right????
                « Reply #29 on: April 10, 2015, 01:06:03 PM »
                Thanks again for all of the advice.