Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving files at specific time

    (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
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving files at specific time

    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!

  3. #3
    5 Star Lounger
    Join Date
    Dec 2002
    Location
    Perth, Western Australia, Australia
    Posts
    730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving files at specific time

    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.
    <font face="Comic Sans MS" color="blue">TimOz</font>
    <img src=/S/flags/Finland.gif border=0 alt=Finland width=30 height=18> <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  4. #4
    Star Lounger
    Join Date
    Nov 2002
    Location
    Port Talbot, Wales
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving files at specific time

    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

  5. #5
    Star Lounger
    Join Date
    Nov 2002
    Location
    Port Talbot, Wales
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving files at specific time

    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

  6. #6
    New Lounger
    Join Date
    Mar 2003
    Location
    New Jersey, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving files at specific time

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •