Solved

VBScript question

Posted on 2006-07-10
9
397 Views
Last Modified: 2012-06-27
Can anyone assist with the below script? I am trying to modify the script so that it will move files from one location to another, however I want to check the files modified date and verify that it has not been changed in 30 minutes so that I do not move a file that is not completely updated.

dim fso as new FileSystemObject  
set fso = new FileSystemObject
fso.CopyFolder "C:\Transferred\GA070706\*", "C:\Transferred\Test\"
set fso = nothing


0
Comment
Question by:ITHCI
  • 4
  • 4
9 Comments
 
LVL 5

Assisted Solution

by:Pi7
Pi7 earned 25 total points
ID: 17074534
you must first test to know if the file has been modified in the last 30 min
to do this use the script

Dim DateCreated As Date
Dim DateModified as Date
Dim LastModified As Integer

DateCreated=fso.GetFile(File).DateCreated
DateModified=fso.GetFile(File).DateLastModified
LastModified=DateDiff("n",DateCreated,DateModified)

If LasModified<=30 Then
      ........'do not copy file
Else
     ........'add you code to copy file
End If

note file is the full path of the file to be copied
0
 
LVL 13

Expert Comment

by:jmundsack
ID: 17074543
   Dim fso As FileSystemObject
    Dim fld As Folder
    Dim fil As File
    Set fso = New FileSystemObject
    Set fld = fso.GetFolder("C:\Transferred\GA070706")
    For Each fil In fld
        If fil.DateLastModified < DateAdd("n", -30, Now) Then
            fil.Copy "C:\Transferred\Test", True
        End If
    Next fil
    Set fil = Nothing
    Set fld = Nothing
    Set fso = Nothing
0
 

Author Comment

by:ITHCI
ID: 17074622
I have the below in a .vbs file and it comes back with the error line 1 char 9 expected end of statement.


Dim fso As FileSystemObject
Dim fld As Folder
Dim fil As File
Set fso = New FileSystemObject
Set fld = fso.GetFolder("C:\Transferred\GA070706")
For Each fil In fld
If fil.DateLastModified < DateAdd("n", -30, Now) Then
fil.Copy "C:\Transferred\Test", True
End If
Next fil
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:jmundsack
ID: 17074816
If you're running this as a script you cannot use explicit object types, as VBScript is untyped--every variable is implicitly a Variant.  Revise as follows:

    Dim fso
    Dim fld
    Dim fil
    Set fso = WScript.CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder("C:\Transferred\GA070706")
    For Each fil In fld
        If fil.DateLastModified < DateAdd("n", -30, Now) Then
            fil.Copy "C:\Transferred\Test", True
        End If
    Next
    Set fil = Nothing
    Set fld = Nothing
    Set fso = Nothing
0
 

Author Comment

by:ITHCI
ID: 17074865
Changed as shown and then I get Line 6 Char 5
error: Object doesnt support this property or method.
Am I doing something else wrong, I am trying to run it as a .vbs file from my desktop.
0
 
LVL 13

Expert Comment

by:jmundsack
ID: 17075005
My mistake...

    For Each fil In fld

...should be:

    For Each fil In fld.Files

0
 

Author Comment

by:ITHCI
ID: 17075095
sorry to be a pain, but one more issue. when I run the file I now get Line 8 Char 13 Error Permission denied. this seems like a directory permission issue but I set it to everyone full so not sure.
0
 
LVL 13

Accepted Solution

by:
jmundsack earned 475 total points
ID: 17075180
I'm very sorry--I feel like a bit of an a** for not testing this code (leave it to us cocky programmers).  Anyway, the problem is you need to specify the full file path in the copy, as follows:

            fil.Copy "C:\Transferred\Test\" & fil.Name, True

0
 

Author Comment

by:ITHCI
ID: 17075280
Thanks works like a charm.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question