Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File Exists Question

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,63757
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File Exists Question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 File Exists Question - 8/23/2008 6:28:42 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
Hello,

How would I go about checking a folder to see if any files are in it, and if there is files copy them to a network drive.

Here is what I have right now, but it seems to not work on *.*

Thanks,

' Filename:  backup.vbs
'
' Author:  Br. David Carlson
'
' Date:  August 4, 2001
'
' This WSH script backs up two files and one folder to M:\Backup.

Dim fso
Dim source1
Dim source2
Dim fileA
Dim fileB
Dim dir
Dim bak

set fso = Wscript.CreateObject("Scripting.FileSystemObject")
source1 = "C:\Courses\Dept\"
source2 = "C:\Courses\"
fileA = "budget2000.xls"
fileB = "agreement.doc"
dir = "Grant"
bak = "M:\Backup"

if Not fso.FolderExists(bak) then
  fso.CreateFolder bak
end if

if fso.FileExists(source1 & fileA) then
  fso.CopyFile source1 & fileA, bak & "\" & fileA
end if

if fso.FileExists(source1 & fileB) then
  fso.CopyFile source1 & fileB, bak & "\" & fileB
end if

if fso.FolderExists(source2 & dir) then
  fso.CopyFolder source2 & dir, bak & "\" & dir
end if


Thanks,

Mike
 
 
Post #: 1
 
 RE: File Exists Question - 8/23/2008 6:39:51 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
*untested*

If fso.FolderExists(strSourceFolder) Then
  Set objFolder = fso.GetFolder(strSourceFolder)
  If objFolder.Files.Count > 0 Then
     fso.CopyFile objFolder.Path & "\*.*", strDestFolder ' make sure the destination folder ends with a \
  End If
End If

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 2
 
 RE: File Exists Question - 8/23/2008 4:20:04 PM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Why not just assume that there ARE files and code for that?
If it turns out that there are NO files in the folder, then the script would just continue on to the next statement.


      


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: File Exists Question - 8/24/2008 1:54:27 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
Thanks to both of you. I was able to get it working correctly.

Thanks Again for the posts.

-Mike

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File Exists Question Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts