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

To print a portion of a filename into a file .txt if only a specific directory exists

Expand Messages
  • Leo
    Hello all, I have a lot of files in the directory c: temp. Some of them have the filename like this: CL00XYZ.zip For each of these files I d like to print
    Message 1 of 3 , Sep 1, 2004
    • 0 Attachment
      Hello all,
      I have a lot of files in the directory c:\temp. Some of them have the filename like this: CL00XYZ.zip

      For each of these files I'd like to print the string CL00XYZ.ZIP into the file cl.txt if only exist the directory c:\temp2\n0XYZ


      For example:

      The directory c:\temp contains:

      CL00100.ZIP
      CL00200.ZIP
      ....
      ABCDEF.ZIP

      In my hard disk exists only the directory c:\temp2\n0100...so I'd like to create a new file (cl.dat) containing only the string CL00100.ZIP


      How can I do ?

      Thanks,
      Leo







      [Non-text portions of this message have been removed]
    • foxidrive
      ... Try this, Leo. @echo off setlocal for /f delims= %%a in ( dir c: temp *.zip /a:-d /b /o:n ) do call :routine %%a goto :EOF ... set name=%~n1 set
      Message 2 of 3 , Sep 1, 2004
      • 0 Attachment
        On Wed, 1 Sep 2004 18:24:50 +0200, you wrote:

        > Hello all, I have a lot of files in the directory c:\temp. Some of them
        > have the filename like this: CL00XYZ.zip
        >
        > For each of these files I'd like to print the string CL00XYZ.ZIP into
        > the file cl.txt if only exist the directory c:\temp2\n0XYZ
        >
        >
        >
        > For example:
        >
        > The directory c:\temp contains:
        >
        > CL00100.ZIP CL00200.ZIP .... ABCDEF.ZIP
        >
        > In my hard disk exists only the directory c:\temp2\n0100...so I'd like
        > to create a new file (cl.dat) containing only the string CL00100.ZIP
        >
        >
        >
        > How can I do ?
        >
        > Thanks, Leo


        Try this, Leo.

        @echo off
        setlocal
        for /f "delims=" %%a in (
        'dir c:\temp\*.zip /a:-d /b /o:n'
        ) do call :routine "%%a"
        goto :EOF

        :routine
        set name=%~n1
        set name=%name:~-4%
        if exist c:\temp2\n%name% echo %~1 >>cl.dat
      • Leo
        It works. Thanks Leo ... From: foxidrive To: batchworld@yahoogroups.com Sent: Thursday, September 02, 2004 5:38 AM Subject: Re: [BATCH WORLD] To print a
        Message 3 of 3 , Sep 2, 2004
        • 0 Attachment
          It works.

          Thanks

          Leo
          ----- Original Message -----
          From: foxidrive
          To: batchworld@yahoogroups.com
          Sent: Thursday, September 02, 2004 5:38 AM
          Subject: Re: [BATCH WORLD] To print a portion of a filename into a file .txt if only a specific directory exists


          On Wed, 1 Sep 2004 18:24:50 +0200, you wrote:

          > Hello all, I have a lot of files in the directory c:\temp. Some of them
          > have the filename like this: CL00XYZ.zip
          >
          > For each of these files I'd like to print the string CL00XYZ.ZIP into
          > the file cl.txt if only exist the directory c:\temp2\n0XYZ
          >
          >
          >
          > For example:
          >
          > The directory c:\temp contains:
          >
          > CL00100.ZIP CL00200.ZIP .... ABCDEF.ZIP
          >
          > In my hard disk exists only the directory c:\temp2\n0100...so I'd like
          > to create a new file (cl.dat) containing only the string CL00100.ZIP
          >
          >
          >
          > How can I do ?
          >
          > Thanks, Leo


          Try this, Leo.

          @echo off
          setlocal
          for /f "delims=" %%a in (
          'dir c:\temp\*.zip /a:-d /b /o:n'
          ) do call :routine "%%a"
          goto :EOF

          :routine
          set name=%~n1
          set name=%name:~-4%
          if exist c:\temp2\n%name% echo %~1 >>cl.dat


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

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


          Yahoo! Groups Sponsor




          ------------------------------------------------------------------------------
          Yahoo! Groups Links

          a.. To visit your group on the web, go to:
          http://groups.yahoo.com/group/batchworld/

          b.. To unsubscribe from this group, send an email to:
          batchworld-unsubscribe@yahoogroups.com

          c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



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