Login | |
|
 |
Searching a folder to see if a file exsists - 10/13/2005 6:11:45 AM
|
|
 |
|
| |
mnman66
Posts: 49
Score: 0
Joined: 3/16/2005
From:
Status: offline
|
Hello guys! Long time no post. Something like 6 months I think. Well, I'm back again for a little bit of help. I'm trying to create a process that searches a specific folder for a number of specific files. Once one of those files are found, I'm running another script to move them with 3rd party software. Here is what I have at this point: Set fso = CreateObject("Scripting.FileSystemObject") srcDir = "C:\Temp\outgoing" On Error Resume Next If fso.FolderExists(srcDir) Then For Each file In fso.GetFolder(srcDir).Files If UCase(Left(fso.GetBaseName(file),4)) = "AGBN" Then Set ws = WScript.CreateObject("WScript.Shell") ws.Run("C:\Temp\AGBN\agbnvs.vbs",0,"True") ElseIf UCase(Left(fso.GetBaseName(file),4)) = "AGTT" Then ws.Run("C:\Temp\AGBN\agttvs.vbs",0,"True") ElseIf UCase(Left(fso.GetBaseName(file),4)) = "AGUS" Then ws.Run("C:\Temp\AGUS\agusvs.vbs",0,"True") ElseIf UCase(Left(fso.GetBaseName(file),4)) = "AGWF" Then ws.Run("C:\Temp\AGWF\agwfvs.vbs",0,"True") ElseIf UCase(Left(fso.GetBaseName(file),4)) = "BLRJ" Then ws.Run("C:\Temp\blrjvs.vbs",0,"True") ElseIf UCase(Left(fso.GetBaseName(file),4)) = "CCRJ" Then ws.Run("C:\Temp\CCRJ\ccrjvs.vbs",0,"True") End If
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/13/2005 8:18:42 AM
|
|
 |
|
| |
Fredledingue
Posts: 383
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
Remove On Error Resume Next. Good scripts don't need that and it will help you find the errors.
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/13/2005 7:02:27 PM
|
|
 |
|
| |
ginolard
Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
|
As a general rule, if you need to use more than 2 If/Then statements you're better of using Select/Case
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/14/2005 1:27:16 AM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
Snipah. Thank you and I see your point but I would think that the location of the scripts is the one thing that he would have the most control over and they would always be where the coder placed them. I am not sure how one would include handling for such an instance without recursively searching all directories for gfName & "vs.vbs". I did put in a way to handle a situation where a gfName did not have a corresponding script located in the script directory. Mnman66 I think that when using "ElseIf" your last condition is made using "Else". Cybex
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/14/2005 1:41:03 AM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
What is this 3rd party software and why do you have to use it to send or copy the file to another server? Cybex
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/14/2005 5:09:21 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Mnman66, try this....: ws.Run "C:\Temp\AGBN\agbnvs.vbs", 0, True -lol-
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/19/2005 5:16:50 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
can you post everything you have so far? This'll help us to get a better understanding of the whole... S
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/19/2005 6:33:37 AM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
I agree with Snipah. Please post everything you have so far so we can see what is going on. Cybex
|
|
| |
|
|
|
 |
RE: Searching a folder to see if a file exsists - 10/19/2005 7:32:10 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Hiya MnMan66, Look here: [..] scrCcrj = "C:\Temp\CCRJ\ccrjvs.vbs" 'very first If If fso.FolderExists(srcDir) Then For Each file In fso.GetFolder(srcDir).Files 'first If If UCase(Left(fso.GetBaseName(file),4)) = "AGBN" Then Set ws = WScript.CreateObject("WScript.Shell") ws.Run(scrAgbn) ElseIf UCase(Left(fso.GetBaseName(file),4)) = "AGTT" Then ws.Run(scrAgtt) [..] If the first If was False Then it would bounce to the next ElseIf, and that is where you didn't put your "Set ws..." hence the error... Put the "Set ws..." before the very first If
< Message edited by Snipah -- 10/19/2005 7:37:12 AM >
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
|
|