Solved

VBScript question

Posted on 2006-07-10
9
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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