Loading ...
Sorry, an error occurred while loading the content.

Renaming files

Expand Messages
  • David Farley
    I have files that transfer to a directory from our system that creates a manifest that gets emailed to the end user that I need to rename from the original
    Message 1 of 21 , Aug 3, 2005
    • 0 Attachment
      I have files that transfer to a directory from our system that creates a
      manifest that gets emailed to the end user that I need to rename from the
      original file name to a shortened name.
      Example: "0000001613_0080114153.txt" but I need it to be
      "1613_0080114153.txt" which is just removing the leading "000000" in the
      file name.
      Dave


      [Non-text portions of this message have been removed]
    • foxidrive
      ... What OS is it for Dave? Are the number of leading zeros variable? -- Regards, Mic
      Message 2 of 21 , Aug 3, 2005
      • 0 Attachment
        On Wed, 3 Aug 2005 07:56:51 -0500, David Farley wrote:

        > I have files that transfer to a directory from our system that creates a
        > manifest that gets emailed to the end user that I need to rename from the
        > original file name to a shortened name.
        > Example: "0000001613_0080114153.txt" but I need it to be
        > "1613_0080114153.txt" which is just removing the leading "000000" in the
        > file name.
        > Dave

        What OS is it for Dave? Are the number of leading zeros variable?


        --
        Regards,
        Mic
      • David Farley
        Sorry about omitting the OS info. It will be running on NT 4 currently but migrating to 2003 server. It should always be 6 leading zeros, at least it is in
        Message 3 of 21 , Aug 3, 2005
        • 0 Attachment
          Sorry about omitting the OS info. It will be running on NT 4 currently but
          migrating to 2003 server.
          It should always be 6 leading zeros, at least it is in every case I have
          seen so far.


          [Non-text portions of this message have been removed]
        • foxidrive
          ... This will work in W2003, but am unsure about NT. If it s for serious work and you really need only leading zeros removed then it ll be a bit more complex.
          Message 4 of 21 , Aug 3, 2005
          • 0 Attachment
            On Wed, 3 Aug 2005 23:32:15 +1000, foxidrive wrote:

            > On Wed, 3 Aug 2005 07:56:51 -0500, David Farley wrote:
            >
            >> I have files that transfer to a directory from our system that creates a
            >> manifest that gets emailed to the end user that I need to rename from the
            >> original file name to a shortened name.
            >> Example: "0000001613_0080114153.txt" but I need it to be
            >> "1613_0080114153.txt" which is just removing the leading "000000" in the
            >> file name.
            >> Dave
            >
            > What OS is it for Dave? Are the number of leading zeros variable?

            This will work in W2003, but am unsure about NT.

            If it's for serious work and you really need only leading zeros removed
            then it'll be a bit more complex.

            @echo off
            set var=%~nx1
            ren %1 "%var:~6%"


            --
            Regards,
            Mic
          • Schelske, Steve K.
            Mic, I give up - can you explain lines 2 & 3? set var=%~nx1 ren %1 %var:~6% ... From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
            Message 5 of 21 , Aug 3, 2005
            • 0 Attachment
              Mic,

              I give up - can you explain lines 2 & 3?

              set var=%~nx1
              ren %1 "%var:~6%"

              -----Original Message-----
              From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
              Behalf Of foxidrive
              Sent: Wednesday, August 03, 2005 12:05 PM
              To: batchworld@yahoogroups.com
              Subject: Re: [BATCH WORLD] Renaming files


              On Wed, 3 Aug 2005 23:32:15 +1000, foxidrive wrote:

              > On Wed, 3 Aug 2005 07:56:51 -0500, David Farley wrote:
              >
              >> I have files that transfer to a directory from our system that creates a
              >> manifest that gets emailed to the end user that I need to rename from the

              >> original file name to a shortened name.
              >> Example: "0000001613_0080114153.txt" but I need it to be
              >> "1613_0080114153.txt" which is just removing the leading "000000" in the
              >> file name.
              >> Dave
              >
              > What OS is it for Dave? Are the number of leading zeros variable?

              This will work in W2003, but am unsure about NT.

              If it's for serious work and you really need only leading zeros removed
              then it'll be a bit more complex.

              @echo off
              set var=%~nx1
              ren %1 "%var:~6%"


              --
              Regards,
              Mic


              To Post a message, send it to: batchworld@...

              To Unsubscribe, send a blank message to: batchworld-unsubscribe@...



              _____

              YAHOO! GROUPS LINKS



              * Visit your group "batchworld
              <http://groups.yahoo.com/group/batchworld> " on the web.


              * To unsubscribe from this group, send an email to:
              batchworld-unsubscribe@yahoogroups.com
              <mailto:batchworld-unsubscribe@yahoogroups.com?subject=Unsubscribe>


              * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
              <http://docs.yahoo.com/info/terms/> .


              _____




              [Non-text portions of this message have been removed]
            • foxidrive
              ... Set the environment variable %var% to the name and extension of the replaceable parameter %1 on the command line. see FOR /? at the bottom for further
              Message 6 of 21 , Aug 3, 2005
              • 0 Attachment
                On Wed, 3 Aug 2005 12:15:09 -0400, Schelske, Steve K. wrote:

                > Mic,
                >
                > I give up - can you explain lines 2 & 3?
                >
                > set var=%~nx1

                Set the environment variable %var% to the name and extension of the
                replaceable parameter %1 on the command line.

                see FOR /? at the bottom for further examples.

                > ren %1 "%var:~6%"

                rename %1 to the varable %var% after skipping 6 characters.

                The format is %var%:~n,m% where n is the number of characters skipped and m
                is the number of characters to use, but various combinations can be used
                including negative numbers to modify the function.

                see SET /? for more help.


                --
                Regards,
                Mic
              • foxidrive
                On Thu, 4 Aug 2005 02:24:30 +1000, foxidrive wrote: Had one too many % in there... %var%:~n,m% was really %var:~n,m% as shown below. ... -- Regards, Mic
                Message 7 of 21 , Aug 3, 2005
                • 0 Attachment
                  On Thu, 4 Aug 2005 02:24:30 +1000, foxidrive wrote:

                  Had one too many % in there... %var%:~n,m% was really %var:~n,m% as shown
                  below.

                  > The format is %var:~n,m% where n is the number of characters skipped and m
                  > is the number of characters to use, but various combinations can be used
                  > including negative numbers to modify the function.
                  >
                  > see SET /? for more help.


                  --
                  Regards,
                  Mic
                • Schelske, Steve K.
                  Thanks you! ... From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On Behalf Of foxidrive Sent: Wednesday, August 03, 2005 12:25 PM To:
                  Message 8 of 21 , Aug 3, 2005
                  • 0 Attachment
                    Thanks you!

                    -----Original Message-----
                    From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                    Behalf Of foxidrive
                    Sent: Wednesday, August 03, 2005 12:25 PM
                    To: batchworld@yahoogroups.com
                    Subject: Re: [BATCH WORLD] Renaming files


                    On Wed, 3 Aug 2005 12:15:09 -0400, Schelske, Steve K. wrote:

                    > Mic,
                    >
                    > I give up - can you explain lines 2 & 3?
                    >
                    > set var=%~nx1

                    Set the environment variable %var% to the name and extension of the
                    replaceable parameter %1 on the command line.

                    see FOR /? at the bottom for further examples.

                    > ren %1 "%var:~6%"

                    rename %1 to the varable %var% after skipping 6 characters.

                    The format is %var%:~n,m% where n is the number of characters skipped and m
                    is the number of characters to use, but various combinations can be used
                    including negative numbers to modify the function.

                    see SET /? for more help.


                    --
                    Regards,
                    Mic


                    To Post a message, send it to: batchworld@...

                    To Unsubscribe, send a blank message to: batchworld-unsubscribe@...



                    _____

                    YAHOO! GROUPS LINKS



                    * Visit your group "batchworld
                    <http://groups.yahoo.com/group/batchworld> " on the web.


                    * To unsubscribe from this group, send an email to:
                    batchworld-unsubscribe@yahoogroups.com
                    <mailto:batchworld-unsubscribe@yahoogroups.com?subject=Unsubscribe>


                    * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
                    <http://docs.yahoo.com/info/terms/> .


                    _____




                    [Non-text portions of this message have been removed]
                  • David Farley
                    Actually it is the leading zeros I need to remove. Zeros are a default filler that is put at the begining of file names that are not as long as the system
                    Message 9 of 21 , Aug 3, 2005
                    • 0 Attachment
                      Actually it is the leading zeros I need to remove. Zeros are a default
                      filler that is put at the begining of file names that are not as long as the
                      system thinks they should be and with the zeros it makes my database lookup
                      not function. If the zeros were gone everything else would funcion
                      perfectly. Currently for these particular files it is putting in 6 zeros,
                      but if the file had been one character longer I suspect it would have put
                      only 5.
                      Dave

                      On 8/3/05, foxidrive <foxidrive@...> wrote:
                      >
                      > On Wed, 3 Aug 2005 23:32:15 +1000, foxidrive wrote:
                      >
                      > > On Wed, 3 Aug 2005 07:56:51 -0500, David Farley wrote:
                      > >
                      > >> I have files that transfer to a directory from our system that creates
                      > a
                      > >> manifest that gets emailed to the end user that I need to rename from
                      > the
                      > >> original file name to a shortened name.
                      > >> Example: "0000001613_0080114153.txt" but I need it to be
                      > >> "1613_0080114153.txt" which is just removing the leading "000000" in
                      > the
                      > >> file name.
                      > >> Dave
                      > >
                      > > What OS is it for Dave? Are the number of leading zeros variable?
                      >
                      > This will work in W2003, but am unsure about NT.
                      >
                      > If it's for serious work and you really need only leading zeros removed
                      > then it'll be a bit more complex.
                      >
                      > @echo off
                      > set var=%~nx1
                      > ren %1 "%var:~6%"
                      >
                      >
                      > --
                      > Regards,
                      > Mic
                      >
                      >
                      > To Post a message, send it to: batchworld@...
                      >
                      > To Unsubscribe, send a blank message to:
                      > batchworld-unsubscribe@...
                      >
                      >
                      > ------------------------------
                      > YAHOO! GROUPS LINKS
                      >
                      >
                      > - Visit your group "batchworld<http://groups.yahoo.com/group/batchworld>"
                      > on the web.
                      > - To unsubscribe from this group, send an email to:
                      > batchworld-unsubscribe@yahoogroups.com<batchworld-unsubscribe@yahoogroups.com?subject=Unsubscribe>
                      > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
                      > Service <http://docs.yahoo.com/info/terms/>.
                      >
                      >
                      > ------------------------------
                      >


                      [Non-text portions of this message have been removed]
                    • foxidrive
                      ... This will rename the filename in parameter %1 and remove all leading zeros, in W2k/XP/ETC - again I am unsure about NT. @echo off set var=%~nx1 ... set
                      Message 10 of 21 , Aug 3, 2005
                      • 0 Attachment
                        On Wed, 3 Aug 2005 15:17:13 -0500, David Farley wrote:

                        > Actually it is the leading zeros I need to remove. Zeros are a default
                        > filler that is put at the begining of file names that are not as long as the
                        > system thinks they should be and with the zeros it makes my database lookup
                        > not function. If the zeros were gone everything else would funcion
                        > perfectly. Currently for these particular files it is putting in 6 zeros,
                        > but if the file had been one character longer I suspect it would have put
                        > only 5.
                        > Dave
                        >
                        > On 8/3/05, foxidrive <foxidrive@...> wrote:
                        >>
                        >> On Wed, 3 Aug 2005 23:32:15 +1000, foxidrive wrote:
                        >>
                        >>> On Wed, 3 Aug 2005 07:56:51 -0500, David Farley wrote:
                        >>>
                        >>>> I have files that transfer to a directory from our system that creates
                        >> a
                        >>>> manifest that gets emailed to the end user that I need to rename from
                        >> the
                        >>>> original file name to a shortened name.
                        >>>> Example: "0000001613_0080114153.txt" but I need it to be
                        >>>> "1613_0080114153.txt" which is just removing the leading "000000" in
                        >> the
                        >>>> file name.
                        >>>> Dave
                        >>>
                        >>> What OS is it for Dave? Are the number of leading zeros variable?
                        >>
                        >> This will work in W2003, but am unsure about NT.
                        >>
                        >> If it's for serious work and you really need only leading zeros removed
                        >> then it'll be a bit more complex.
                        >>
                        >> @echo off
                        >> set var=%~nx1
                        >> ren %1 "%var:~6%"

                        This will rename the filename in parameter %1 and remove all leading zeros,
                        in W2k/XP/ETC - again I am unsure about NT.

                        @echo off
                        set var=%~nx1
                        :loop
                        set var=%var:*0=%
                        if "%var:~0,1%"=="0" goto :loop
                        ren %1 "%var%"



                        --
                        Regards,
                        Mic
                      • David Farley
                        Okay, can you help me understand how this works? I get the first set command as it expands the variable to a file name and extension. The :loop lets it know
                        Message 11 of 21 , Aug 5, 2005
                        • 0 Attachment
                          Okay, can you help me understand how this works?
                          I get the first set command as it expands the variable to a file name and
                          extension.
                          The :loop lets it know where to go with the goto :loop.
                          The next line I am lost with the %var:*0,1=%, and the if "var:~0,1%" portion
                          of the next line.
                          The last line I have an idea what it is doing but not fully, but I know what
                          outcome we are trying to get to.
                          Any knowledge transfer on this is appreciated.
                          Thanks,
                          Dave


                          [Non-text portions of this message have been removed]
                        • foxidrive
                          ... You highlighted a potential problem, where the filename did not have a leading 0 but it did contain a 0. That s fixed below. %var:~0,1% resolves to the
                          Message 12 of 21 , Aug 5, 2005
                          • 0 Attachment
                            On Fri, 5 Aug 2005 15:09:32 -0500, David Farley wrote:

                            > Okay, can you help me understand how this works?
                            > I get the first set command as it expands the variable to a file name and
                            > extension.
                            > The :loop lets it know where to go with the goto :loop.
                            > The next line I am lost with the %var:*0,1=%, and the if "var:~0,1%" portion

                            You highlighted a potential problem, where the filename did not have a
                            leading 0 but it did contain a 0. That's fixed below.

                            "%var:~0,1%" resolves to the first character in %var%
                            (skip 0 characters, and then take the next 1)


                            set var=%var:*0=% is a special case of the set var=%var:a=b% syntax.

                            set var=%var:a=b% will replace all a characters with b and the source
                            character is case insensitive.

                            set var=%var:a=% will remove all a characters

                            set var=%var:*0=% will remove all characters from the start of the line (*)
                            up to and including the first 0 character.

                            See SET /? for the help.



                            This will rename the filename in parameter %1 and remove all leading zeros,
                            in W2k/XP/ETC - again I am unsure about NT.

                            @echo off
                            set var=%~nx1
                            :loop
                            if "%var:~0,1%"=="0" set var=%var:*0=%
                            if "%var:~0,1%"=="0" goto :loop
                            ren %1 "%var%"




                            --
                            Regards,
                            Mic
                          • David Farley
                            Thank you for taking the time to help me understand this batch file. Dave [Non-text portions of this message have been removed]
                            Message 13 of 21 , Aug 7, 2005
                            • 0 Attachment
                              Thank you for taking the time to help me understand this batch file.
                              Dave


                              [Non-text portions of this message have been removed]
                            Your message has been successfully submitted and would be delivered to recipients shortly.