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

Author Topic: bat file to copy files from folder with changing name YYYYMMDD  (Read 9316 times)

0 Members and 1 Guest are viewing this topic.

jonfrye

    Topic Starter


    Starter

    bat file to copy files from folder with changing name YYYYMMDD
    « on: February 13, 2010, 10:07:44 AM »
    I am needing to write a bat file that copies files from a folder whose name changes daily and I need to copy those from yesterdays folder. I.e. if today is feb 12, 2010 i need to copy files from folder 20100211 and tomorrow I will need to copy from folder 20100212. Can anyone help me? Thanks in advance

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: bat file to copy files from folder with changing name YYYYMMDD
    « Reply #1 on: February 13, 2010, 10:11:30 AM »
    Open up the command prompt and type in
    Code: [Select]
    echo %date% then post what is displayed on the screen. We need to know this so we can make a code that works for your date format.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    jonfrye

      Topic Starter


      Starter

      Re: bat file to copy files from folder with changing name YYYYMMDD
      « Reply #2 on: February 13, 2010, 10:16:53 AM »
      it's :     Sat 02/13/2010

      Salmon Trout

      • Guest
      Re: bat file to copy files from folder with changing name YYYYMMDD
      « Reply #3 on: February 13, 2010, 02:28:09 PM »
      Watch out for the end-of-the-month...

      jonfrye

        Topic Starter


        Starter

        Re: bat file to copy files from folder with changing name YYYYMMDD
        « Reply #4 on: February 14, 2010, 02:20:43 PM »
        i could also approach this by copying contents of the most recent folder where folder name is like YYYYMMDD to a folder named current.  Would this make it any more doable?

        Salmon Trout

        • Guest
        Re: bat file to copy files from folder with changing name YYYYMMDD
        « Reply #5 on: February 14, 2010, 02:22:46 PM »
        pls answer helpmeh's question.

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        Salmon Trout

        • Guest
        Re: bat file to copy files from folder with changing name YYYYMMDD
        « Reply #7 on: February 14, 2010, 03:39:26 PM »


        Sorry I must be going blind. Anyhow, we don't really need the date format if we can use VBS.

        Code: [Select]
        @echo off
        Echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs
        For /f "delims=" %%A in ('cscript //nologo evaluate.vbs  "year(date-1)"') do set YYYY=%%A
        For /f "delims=" %%B in ('cscript //nologo evaluate.vbs "month(date-1)"') do set MM=%%B
        For /f "delims=" %%C in ('cscript //nologo evaluate.vbs   "day(date-1)"') do set DD=%%C
        del evaluate.vbs
        if %MM% LSS 10 set MM=0%MM%
        if %DD% LSS 10 set DD=0%DD%
        set sourcefolder=%YYYY%%MM%%DD%
        set filespec=*.*
        set destinfolder=c:\whatever\whatever
        copy "%sourcefolder%\%filespec%" "%destinfolder%"






        jonfrye

          Topic Starter


          Starter

          Re: bat file to copy files from folder with changing name YYYYMMDD
          « Reply #8 on: February 14, 2010, 07:04:41 PM »
          Outstanding, thanks very much--I appreciate it immensely.

          ghostdog74



            Specialist

            Thanked: 27
            Re: bat file to copy files from folder with changing name YYYYMMDD
            « Reply #9 on: February 14, 2010, 08:30:17 PM »

            Code: [Select]
            @echo off
            ....
            Echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs
            For /f "delims=" %%A in ('cscript //nologo evaluate.vbs  "year(date-1)"') do set YYYY=%%A
            For /f "delims=" %%B in ('cscript //nologo evaluate.vbs "month(date-1)"') do set MM=%%B
            For /f "delims=" %%C in ('cscript //nologo evaluate.vbs   "day(date-1)"') do set DD=%%C

            this can be shortened (by combining the evals) so that you don't have to call cscript.exe engine 3 times.

            Salmon Trout

            • Guest
            Re: bat file to copy files from folder with changing name YYYYMMDD
            « Reply #10 on: February 15, 2010, 12:28:58 AM »
            this can be shortened (by combining the evals) so that you don't have to call cscript.exe engine 3 times.

            Indeed. And you can eliminate the parameter passing altogether.

            Code: [Select]
            @echo off
            REM must use sign - or +
            set diff= -1
            Echo Wscript.echo year(date%diff%) ^& "," ^& month(date%diff%) ^& "," ^& day(date%diff%)>datecalc.vbs
            For /f "tokens=1-3 delims=," %%A in ('cscript //nologo datecalc.vbs') do (
                set YYYY=%%A
                set MM=%%B
                set DD=%%C
                )
            del datecalc.vbs
            if %MM% LSS 10 set MM=0%MM%
            if %DD% LSS 10 set DD=0%DD%
            set foldername=%YYYY%%MM%%DD%
            « Last Edit: February 15, 2010, 01:31:30 AM by Salmon Trout »