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

Author Topic: xcopy certain dates or certain folders help.  (Read 4305 times)

0 Members and 1 Guest are viewing this topic.

jamster69

    Topic Starter


    Starter

    xcopy certain dates or certain folders help.
    « on: September 27, 2009, 07:45:02 AM »
    Hi I'm pretty new to batch files so here goes,
    I'm looking to xcopy certain log files but exclude others from being copied,
    for eg the log files are named by date 200909026 through to 200400101. so i want to xcopy only from 20040101 to 20090901 and leave the rest.
    Could some one point me to the correct syntax please.
    Thanksyou.


    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: xcopy certain dates or certain folders help.
    « Reply #1 on: September 27, 2009, 09:56:40 AM »
    @echo off
    Set mindate=20040101
    Set maxdate=20090901
    For /f "tokens=1,2 delims=." %%a in ('dir /b *.log') do if not "%%a" LSS "%mindate%" if not "%%a" gtr "%maxdate%" copy %%a.%%b TARGETLOCATION

    That should do it. It's not tested though.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    jamster69

      Topic Starter


      Starter

      Re: xcopy certain dates or certain folders help.
      « Reply #2 on: September 27, 2009, 10:12:55 AM »
      Thank for your response helpmeh,
      could you explanin some of the syntax pls so i have a better understanding in the future

      jamster69

        Topic Starter


        Starter

        Re: xcopy certain dates or certain folders help.
        « Reply #3 on: September 27, 2009, 10:24:21 AM »
        I have another question i wrote this simple batch file:

        start /d "C:\program Files\test" packer.exe

        start /wait/b XCOPY "C:\program files\Archived Logs"  "D:\Archived logs"  /E /V /C /I /Q /H /K /O /X /Y

        basically whats mean to happen is packer.exe program zipps up a log file then creates a folder called  and C:\program files\Archived Logs and inserts it in there which works ok but then when this is finished i want to copy the latest zipped file from the archived folder to D:\Archived logs , the xcopy part is not working. But does work if i run the batch file twice,i think the batch file needs to wait until packer.exe completes ,
        What am i doing wrong ?
        Thanks


        jamster69

          Topic Starter


          Starter

          Re: xcopy certain dates or certain folders help.
          « Reply #4 on: September 27, 2009, 10:41:03 AM »
          sorry should be

           tart /d "C:\program Files\test" packer.exe

          start /wait/b XCOPY "C:\program files\Archived Logs\"*"  "D:\Archived logs"  /E /V /C /I /Q /H /K /O /X /Y

          Still working though ,

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: xcopy certain dates or certain folders help.
          « Reply #5 on: September 27, 2009, 03:33:17 PM »
          Thank for your response helpmeh,
          could you explanin some of the syntax pls so i have a better understanding in the future
          Well, the set command should be fairly obvious to you. But here's how the for loop works.

          for /f
          The command with the /f switch. See FOR /? for more information on other switches.

          "tokens=1,2
          Part one of the options. Specifies that the first 2 tokens are used. By default is 1.

          delims=."
          Part 2 of the options. It tells the command where to divide the output (see later) by for each token. Must be used last. By default is a space and/or a tab.

          %%a
          Specifies the first for variable (or the only one in some cases).

          in
          (self-explanitory)

          ('dir /b *.log')
          Collects the output from that command (see DIR /? for more info on that command).

          do
          (self-explanitory)

          If not "%%a" LSS "%mindate%"
          If the value of %%a is not less than the value of %mindate% do:

          If not "%%a" gtr "%maxdate%"
          If the value of %%a is not greater than the value of %maxdate% do:

          Copy %%a.%%b TARGETLOCATION
          Copy the value of %%a.%%b (which is the file's name .log ex 20090801.log) to the target location (TARGETLOCATION), which you had to specify.

          If you need any more help, feel free to ask.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.