Solved

VBScript question

Posted on 2006-07-10
9
376 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now