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

Author Topic: Copying files created today and deleting old files  (Read 2713 times)

0 Members and 1 Guest are viewing this topic.

oba_shonowo

    Topic Starter


    Greenhorn

    Copying files created today and deleting old files
    « on: April 02, 2008, 03:30:34 AM »
    Hello all. I am trying to use a command to copy a file that is created daily, move it to a folder on another machine and delete all the old versions of that file on the second machine.

    Can anyone give me some guidiance on how it can be done on a Windows 2003 box.

    Spoiler



      Specialist

      Thanked: 50
    • Experience: Beginner
    • OS: Windows XP
    Re: Copying files created today and deleting old files
    « Reply #1 on: April 02, 2008, 07:46:48 AM »
    How about a Batch file?

    DEL \\machine\share\old*.txt
    Copy C:\path \\machine\share\file.txt

    Whenever I watch TV and I see those poor starving kids all over the world, I can't help but cry. I mean I would love to be skinny like that, but not with all those flies and death and stuff." - Mariah Carey, Pop Singer

    oba_shonowo

      Topic Starter


      Greenhorn

      Re: Copying files created today and deleting old files
      « Reply #2 on: April 03, 2008, 01:52:18 AM »
      This is what I currently have:

      copy F:\sqldata\MSSQL\BACKUP\master\*.BAK "\\172.25.32.6\d$\FEP\FEP Script Backup\master"
      pause

      I use * because I don't know how to pick then one for the current day. The other problem is I need to delete all the old ones in "\\172.25.32.6\d$\FEP\FEP Script Backup\master".

      Pls help.

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Copying files created today and deleting old files
      « Reply #3 on: April 03, 2008, 05:15:41 AM »
      Batch code does not do date arithmetic very well. If the file to be copied has the most recent date, this little piece of doggerel should help:

      Code: [Select]
      @echo off
      del "\\172.25.32.6\d$\FEP\FEP Script Backup\master\*.*"
      for /f "tokens=* delims=" %%v in ('dir /o:-d /s /b F:\sqldata\MSSQL\BACKUP\master\*.BAK') do (
      copy %%v "\\172.25.32.6\d$\FEP\FEP Script Backup\master"
      goto end
      )
      :end

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

      -- Albert Einstein

      oba_shonowo

        Topic Starter


        Greenhorn

        Re: Copying files created today and deleting old files
        « Reply #4 on: April 18, 2008, 06:09:51 AM »
        Thanks. It worked. I used skip to replace the go to label. I also reversed the list given by the dir command to do the correct delete.