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

Author Topic: Batch file to execute a command in the most recent folder at a specific place  (Read 5495 times)

0 Members and 1 Guest are viewing this topic.

ajspruit

    Topic Starter


    Newbie

    Hi All

    I'm hoping someone can help me with the following, I'm currently running WINXP but will need to be compatible with WIN2000.

    I'm trying to create a batch file that will execute a copy command of the most recent folder at a specific location.

    i.e.
    I have a folder structure where my production builds go (e:\workspace\2.6; 2.7; 2.8), within these folders a new build is populate to then simple called 2.6_test_1; 2; 3 ; 4 etc... and there are only two 'builds' keep in each folder at any one time. I want to create a batch file that will determine which build is most recent (either by build number or date) and then executed a copy command from within that folder.

    I really really hope this makes sense to someone other then me and if anyone can help it would be very much appreciated

    regards
    AJ

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Quote
    I really really hope this makes sense to someone other then me

    Not so much. I figure your folder structure looks something like this:

    Quote
    workspace
    |
    |__2.6
    |  |__2.6_test_1
    |  |__2.6_test_2
    |  |__2.6_test_3
    |  |__2.6_test_4   
    |
    |__2.7
    |  |__2.7_test_1
    |  |__2.7_test_2
    |  |__2.7_test_3
    |  |__2.7_test_4 
    |
    |__2.8
    |  |__2.8_test_1
    |  |__2.8_test_2
    |  |__2.8_test_3
    |  |__2.8_test_4 

    Now please explain the source and target of this copy you want to do.

    Quote
    I want to create a batch file that will determine which build is most recent (either by build number or date)

    This is where I get lost. If it's true that build number 2.8_test_4 is more recent than 2.6_test_4, you could sort the folders descending by date, take the first folder in the list and sort the build files descending by date. The file at the top of the list would be the most recent build.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    ajspruit

      Topic Starter


      Newbie

      Hi Sidewinder

      The folder structure does indeed look like that with possibly 4 or 5 builds added to each folder daily.

      What i would like to be able to do is at any point in the day run a batch file that will go and pick up the 'newest' build from each folder and copy these to another location, The copy part of the batch file isn't a problem but i need a way for the batch file to determine what the 'newest' build is in each folder regardless of what number that build might be.

      I understand that this is quite tricky due to the way microsoft set there dates but I'm hoping there is a way i can get it to pick up the 'hightest' build number from each folder.

      does that help any?

      thanks again
      aj


      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Quote
      I understand that this is quite tricky due to the way microsoft set there dates

      Actually not. The display dates are locally formated by the user. The dates are stored internally in Universal Time Coordinate (UTC) format.

      Quote
      What i would like to be able to do is at any point in the day run a batch file that will go and pick up the 'newest' build from each folder and copy these to another location

      This may help:

      Code: [Select]
      @echo off
      setlocal enabledelayedexpansion
      for /f "tokens=* delims=" %%v in ('dir e:\workspace /b /a:d') do (
      set first=Y
      for /f "tokens=* delims=" %%x in ('dir e:\workspace\%%v /a:-d /b /o:-d') do (
      if !first!==Y copy e:\workspace\%%v\%%x .....
      set first=N
      )
      )

      Based on your naming convention, be sure not to overwrite any files. The copy statement is incomplete, used for demo purposes.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein