• Moving files at specific time

    Home » Forums » AskWoody support » Windows » Windows – other » Moving files at specific time

    Author
    Topic
    #383227

    (Env: Win2K, Of2K (UK)

    Hi, (HELP !!)

    I’m a newbie to scripts and windows programming.

    Would like to, every morning at 5:00 transfer all .WMF files in a network folder (and its subfolders) to another folder on another mapped network drive.- existing files should be overwritten.

    I can’t really make heads or tales of where to start.
    Come across WSH (eg. SHFILEOPSTRUCT) , API “FileCopy”/”FileMove”), VB “filesearch” etc. etc.

    As I see it I need to break it into three:
    1. setting a timer
    2. Identifying the files to copy or move
    3. Do the actual copy/move

    Suggestions for a good approach through this, will be highly appreciated.

    Thanks,
    ;o) Henrik

    Viewing 1 reply thread
    Author
    Replies
    • #652846

      I would expect you could do it with a simple batch file, scheduled to run when you require. See if this DOS Batch Files page helps, or come back and ask!

      • #652850

        Something like:

        @ECHO OFF
        CD d:destinationfolder
        XCOPY s:sourcefolder*.WMF /S /Y

        (Replacing “d:destinationfolder” with where you want the files to be, and “s:sourcefolder” with where they are.)

        If ‘transfer’ meant ‘move’ then you could either append a DEL after the XCOPY, or get fancy with FOR and MOVE.

        • #658498

          Or you could create a VB executable and schedule it for when you want. I’ve wrote the code below very quickly and havn’t had a chance to test it so apoligies if there are any mistakes. Feel free to pick holes in it too.

          Function FileExists(Fname) As Boolean
          ‘different method from <FileExists = Dir(Fname) “”>
          ‘so not to conflict with dir in calling subroutine
          Dim GA As Long

          On Error GoTo NoFile
          GA = GetAttr(Fname)
          FileExists = True
          Exit Function

          NoFile:
          If Err.Number = 53 Or Err.Number = 68 Then
          FileExists = False
          Else
          MsgBox Fname & Chr(13) & Err.Number & Chr(13) & Err.Description, , “File Exists Function”
          End
          End If
          End Function

          Sub Main()
          ‘Declare Variables
          Dim OldFN as String, NewFN as String
          Dim OldFP as String, NewFP as String

          ‘Set FIle Paths
          OldFP = “The Path To Move Files From”
          NewFP = “The Path To Move Files To”

          ‘Change To Drive Where Files To Be Moved From
          ChDrive(Left(OldFP,1))
          ‘Change To Directory Where Files To Be Moved From
          ChDir(OldFP)
          OldFN = Dir(“*.*”)

          Do While OldFN “”
          ‘Set New FilePath and FileName
          NewFN = NewFP & OldFN
          ‘If The FIleExists Then Delete It
          If FileExists(NewFN) then Kill(NewFN)
          ‘Move File To New Location
          Name OldFN As NewFN
          ‘Reset OldFilename For Next File
          OldFN = Dir(“*.*”)
          Loop

          End Sub

          Regards
          Jamie

        • #658510

          Or you could create a VB executable and schedule it for when you want. I’ve wrote the code below very quickly and havn’t had a chance to test it so apoligies if there are any mistakes. Feel free to pick holes in it too.

          Function FileExists(Fname) As Boolean
          ‘different method from <FileExists = Dir(Fname) “”>
          ‘so not to conflict with dir in calling subroutine
          Dim GA As Long

          On Error GoTo NoFile
          GA = GetAttr(Fname)
          FileExists = True
          Exit Function

          NoFile:
          If Err.Number = 53 Or Err.Number = 68 Then
          FileExists = False
          Else
          MsgBox Fname & Chr(13) & Err.Number & Chr(13) & Err.Description, , “File Exists Function”
          End
          End If
          End Function

          Sub Main()
          ‘Declare Variables
          Dim OldFN as String, NewFN as String
          Dim OldFP as String, NewFP as String

          ‘Set FIle Paths
          OldFP = “The Path To Move Files From”
          NewFP = “The Path To Move Files To”

          ‘Change To Drive Where Files To Be Moved From
          ChDrive(Left(OldFP,1))
          ‘Change To Directory Where Files To Be Moved From
          ChDir(OldFP)
          OldFN = Dir(“*.*”)

          Do While OldFN “”
          ‘Set New FilePath and FileName
          NewFN = NewFP & OldFN
          ‘If The FIleExists Then Delete It
          If FileExists(NewFN) then Kill(NewFN)
          ‘Move File To New Location
          Name OldFN As NewFN
          ‘Reset OldFilename For Next File
          OldFN = Dir(“*.*”)
          Loop

          End Sub

          Regards
          Jamie

    • #658774

      I’ve done this exact thing in Win98SE. Not sure if it will work in 2000 or XP or across a network (i.e. if you use networkdrivedirectory as a target). I created a PIF file for the following batch file and scheduled it to run using Task Scheduler. The batch copies any files that are new and overwrites any existing files in the target destination that are older than those being copied. Any existing unchanged files in the target directory are left intact:

      C:WINDOWSCOMMANDXCOPY.EXE d:source e:target /e /d /y /c

      Switches:
      /c
      Ignores errors (to prevent batch from failing in case a file is, say, marked read only, or some other condition that would halt batch).
      /d[:date]
      Copies only source files changed on or after the specified date.
      /e
      Copies all subdirectories, even if they are empty.
      /y
      Overwites existing files without prompting.

    Viewing 1 reply thread
    Reply To: Moving files at specific time

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: