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

Author Topic: copy files that created today  (Read 25488 times)

0 Members and 1 Guest are viewing this topic.

kalmazz

    Topic Starter


    Rookie

    Thanked: 1
    copy files that created today
    « on: May 21, 2009, 01:58:05 AM »
    Hi Gurus,

    I want to create a batch file and put in WINXP shecdule ,

    THAT COPIES THE FILES THOSE ARE CREATED ON THE DAY WHEN THE BATCHFILE IS EXECUTED TO ANOTHER LOCATION.


    Hedonist



      Intermediate

      Re: copy files that created today
      « Reply #1 on: May 21, 2009, 03:05:39 AM »
      Are all the files in one folder or spread around the file system?

      kalmazz

        Topic Starter


        Rookie

        Thanked: 1
        Re: copy files that created today
        « Reply #2 on: May 21, 2009, 03:18:41 AM »
        They are in one  folder.

        Reno



          Hopeful
        • Thanked: 32
          Re: copy files that created today
          « Reply #3 on: May 21, 2009, 07:12:32 AM »
          method 1: use xcopy /d

          method 2:use for loop & dir
          Code: [Select]
          @echo off
          for /f "skip=1 tokens=1-3*" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
          if %%a==%date:~-10% (
          echo %%a %%d
          copy "%%d" "c:\backup\
          ) else goto:eof
          )

          method 3: use vbscript
          Code: [Select]
          set fso=createobject("scripting.filesystemobject")
          for each f in fso.getfolder(".").files
          if datediff("d",f.datecreated,date())=0 then
          wsh.echo f.datecreated,f
          f.copy "c:\backup\"
          end if
          next
          at cmd prompt, type cscript//nologo backup.vbs

          kalmazz

            Topic Starter


            Rookie

            Thanked: 1
            Re: copy files that created today
            « Reply #4 on: May 23, 2009, 12:18:11 AM »
            Thanks, I used method 2.
            But It gaves the message " The specified file cannot be found" . I have attached the screen shot.
            What I need is :
            Copy the ONLY THE file that created today to another folder.

            [attachment deleted by admin]

            Dusty



              Egghead

            • I could if she would, but she won't so I don't.
            • Thanked: 75
            • Experience: Beginner
            • OS: Windows XP
            Re: copy files that created today
            « Reply #5 on: May 23, 2009, 02:31:53 AM »
            Code: [Select]
            copy "%%d" "c:\backup\"
            Have you created the destination folder?

            One good deed is worth more than a year of good intentions.

            kalmazz

              Topic Starter


              Rookie

              Thanked: 1
              Re: copy files that created today
              « Reply #6 on: May 23, 2009, 05:24:30 AM »
              yes,  i have created the destination folder c:\backup

              Reno



                Hopeful
              • Thanked: 32
                Re: copy files that created today
                « Reply #7 on: May 23, 2009, 05:49:19 AM »
                my mistake, i didn't take account for time format "hh:mm am/pm"

                updated code that support both 12h and 24h format:
                Code: [Select]
                @echo off & setlocal
                time/t|find "M" && set t=1,4* || set t=1,3*

                for /f "skip=1 tokens=%t%" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
                if %%a==%date:~-10% (
                echo %%a %%c
                copy "%%c" "c:\backup\"
                ) else goto:eof
                )
                « Last Edit: May 23, 2009, 06:05:01 AM by Reno »

                kalmazz

                  Topic Starter


                  Rookie

                  Thanked: 1
                  Re: copy files that created today
                  « Reply #8 on: May 23, 2009, 06:30:36 AM »
                  I tried it , but still it is same.
                  Date format is the problem ?


                  [attachment deleted by admin]

                  Reno



                    Hopeful
                  • Thanked: 32
                    Re: copy files that created today
                    « Reply #9 on: May 23, 2009, 06:53:40 AM »
                    I tried it , but still it is same.
                    Date format is the problem ?
                    no, i have take account for both date format, ddd mm/dd/yyyy or mm/dd/yyyy.

                    double check the code, try to copy & paste all the new code again at post#8. if your time format is 12h, it should display current time on the first line when the batch is executed.

                    additional check (type at cmd prompt):
                    Code: [Select]
                    time/t
                    time/t|find "M" && (echo 12h) || echo 24h
                    and tell me what the result

                    kalmazz

                      Topic Starter


                      Rookie

                      Thanked: 1
                      Re: copy files that created today
                      « Reply #10 on: May 23, 2009, 11:37:03 PM »
                      Thanks,
                      IT IS DONE  :)

                      TheShadow



                        Hopeful

                      • Retiree in Florida
                      • Thanked: 13
                        • Yes
                        • The Doctor
                      • Certifications: List
                      • Computer: Specs
                      • Experience: Guru
                      • OS: Windows XP
                      Re: copy files that created today
                      « Reply #11 on: May 25, 2009, 07:09:15 AM »
                      If you miss a day, you'll also miss copying some files because you're limiting your copy to just the files created "Today".

                      If you're using this batch file as a means of backing up critical data files, you might just want to use a broader criteria for the files being copied.

                      I use XCOPY to keep all my data files on C: backed up to D:

                      I just incorporated the XCOPY lines into my end of day shutdown script (batch file).

                      When done properly, with the correct switches, xcopy copies only files that are either new or have been updated since the last backup.
                      My batch file looks something like this:

                      Quote
                      @Echo off
                      cls
                      Rem Backup My Documents and all sub-folders/files.
                      xcopy "C:\Documents and Settings\Alex\My Documents\*.*" "D:\My Documents\" /s /y /H /R /D

                      Rem Back up my WordPerfect files.
                      xcopy "C:\MyFiles\*.*" "D:\MyFiles\" /s /y /H /R /D

                      Rem Back up all the files for My Web Page.
                      xcopy "C:\My web page\*.*" "D:\My web page\" /s /y /H /R /D

                      Rem Back up my email folders.
                      xcopy "C:\Documents and Settings\Alex\Local Settings\Application Data\Identities\{CC1A6FC7-0D07-4169-865D-56EBDD76EB8B}\Microsoft\Outlook Express\*.dbx"  "D:\MyEmailFiles-Backup\" /s /y /H /R /D

                      Rem  When the backup is done...Shutdown!

                      %windir%\System32\shutdown.exe -s -t 00 -f

                      On an average day, I may be backing up only one or two files, so the batch file runs and finishes in just a few seconds.  It assures that I never shut down my PC with unsaved data files.
                      In this case D: is my backup hard drive.

                      Batch files can get really complicated or you can "KEEP IT SIMPLE".
                      Just add lines to accommodate any folders in your PC that contain valuable data.
                      That would be different for each person.

                      Even though I make a Ghost backup of my entire C: drive, at least once a week, my shutdown batch file assures that I keep all my data files backed up between Ghost backups.

                      So, don't loose your stuff to a HD crash.
                      Backup, Backup, Backup!!!

                      The Shadow  8)

                      Experience is truly the best teacher.
                      Backup! Backup! Backup!  Ghost Rocks!

                      BC_Programmer


                        Mastermind
                      • Typing is no substitute for thinking.
                      • Thanked: 1140
                        • Yes
                        • Yes
                        • BC-Programming.com
                      • Certifications: List
                      • Computer: Specs
                      • Experience: Beginner
                      • OS: Windows 11
                      Re: copy files that created today
                      « Reply #12 on: May 25, 2009, 12:01:41 PM »
                      thanks for the reminder- I myself have been meaning to perform some file management. my 500GB drive is running out of space  :o
                      I was trying to dereference Null Pointers before it was cool.

                      kalmazz

                        Topic Starter


                        Rookie

                        Thanked: 1
                        Re: copy files that created today
                        « Reply #13 on: May 27, 2009, 07:59:55 AM »
                        Thanks for your information on backups.
                        I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
                        I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
                        How do I do it in a batch file ?

                         

                        Reno



                          Hopeful
                        • Thanked: 32
                          Re: copy files that created today
                          « Reply #14 on: May 28, 2009, 12:39:10 AM »
                          Thanks for your information on backups.
                          I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
                          I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
                          How do I do it in a batch file ?
                          since this question is being ask a lot from day to day, here is an example .hta script.

                          this is my first hta script, so the code is messy & dirty.
                          i couldn't get the progressbar image to work properly and showing file being copied interactively.
                          feel free to modify the code in notepad, it is basically a vbscript wrapped inside html code.
                          WARNING: use at your own risk!!! test first on testing folder

                          [attachment deleted by admin]