Jump to content

Recommended Posts

Posted

Hello,

Does anyone have a VB Script that will check a specific folder on a Windows 2000 box for files created only in the last day and move them to another specified folder?

Thanks.


Posted

Here is an example which does as your question above asks.

' folder where the files reside
sSourceFolder = "C:\mysource"

' folder to where files are moved
sTargetFolder = "C:\mytarget"

dDate = Date
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sSourceFolder)
For Each oFile In oFolder.Files
If DateDiff("d", oFile.DateCreated, dDate) = 0 Then
oFile.Move sTargetFolder & "\", True
End If
Next

However from your Subject Title I doubt that this is exactly what you want. You mention FTP, which may mean some files may already exist in the second location making File.Move a bad idea, some files may have been changed, but still have the same DateCreated etc.

Posted
Why use a script? Check out Robocopy from Microsoft. a single CMD line with it will do what is sounds like you want.

I looked at the RoboCopy. It doesn't allow me to set a time frame of which to copy files. For instance. I only want to get files that were created in the last 3 days. It doesn't seem to allow me to specify the time of which to only copy the files.

Thanks for the suggestion tho'.

Yzöwl I'm going to give this script a try. I'll keep you posted.

Thanks.

Posted

I believe you are after the MAXAGE or MINAGE switches.

From Robocopy /? help:

::

:: File Selection Options :

::

/A :: copy only files with the Archive attribute set.

/M :: copy only files with the Archive attribute and reset it.

/IA:[RASHCNETO] :: Include only files with any of the given Attributes set.

/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set.

/XF file [file]... :: eXclude Files matching given names/paths/wildcards.

/XD dirs [dirs]... :: eXclude Directories matching given names/paths.

/XC :: eXclude Changed files.

/XN :: eXclude Newer files.

/XO :: eXclude Older files.

/XX :: eXclude eXtra files and directories.

/XL :: eXclude Lonely files and directories.

/IS :: Include Same files.

/IT :: Include Tweaked files.

/MAX:n :: MAXimum file size - exclude files bigger than n bytes.

/MIN:n :: MINimum file size - exclude files smaller than n bytes.

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.

/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.

/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.

/MINLAD:n :: MINimum Last Access Date - exclude files used since n.

(If n < 1900 then n = n days, else n = YYYYMMDD date).

/XJ :: eXclude Junction points. (normally included by default).

Posted
Here is an example which does as your question above asks.
' folder where the files reside
sSourceFolder = "C:\mysource"

' folder to where files are moved
sTargetFolder = "C:\mytarget"

dDate = Date
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sSourceFolder)
For Each oFile In oFolder.Files
If DateDiff("d", oFile.DateCreated, dDate) = 0 Then
oFile.Move sTargetFolder & "\", True
End If
Next

However from your Subject Title I doubt that this is exactly what you want. You mention FTP, which may mean some files may already exist in the second location making File.Move a bad idea, some files may have been changed, but still have the same DateCreated etc.

what is the format for the Date?

Posted

In order to find out, create a vbs containing this:

wscript.echo date

and double-click it.

I looked at the RoboCopy. It doesn't allow me to set a time frame of which to copy files. For instance. I only want to get files that were created in the last 3 days. It doesn't seem to allow me to specify the time of which to only copy the files.
As IcemanND has mentioned, try
/MAXAGE:3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...