[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBScript question

Posted on 2006-07-10
9
Medium Priority
?
417 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 100 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1900 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

Industry Leaders: 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!

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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