Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking to see if mutiple files exits, using a textfile values

Status
Not open for further replies.

flybravo

Programmer
Jun 30, 2003
35
US
This is what I have done so far. I need to be able to check to see if all of the files exists. The file names will come from a list in a text file. Currently I get a mismatch error when the code executes at the IF/THEN statements

CODE
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOpen = objFSO.OpenTextFile("C:\AIX36009_Req.txt", ForReading)
Dim arrFileName()

i = 0
Do While objOpen.AtEndOfStream <> true
text = objOpen.ReadLine
'WSCript.Echo text
ReDim Preserve arrFileName(i)
arrFileName(i) = text
i=i+1
loop
objOpen.Close
Set objOpen = Nothing

'WSCript.Echo arrFilename(0)

'text = &quot;objFSO.FileExists(&quot; & arrFilename(0) & &quot;)&quot;
'WSCript.Echo text

For i=0 to UBound(arrFileName)
'WScript.Echo arrFileName(i)
strNextDocument = &quot;(objFSO.FileExists(&quot;&quot;&quot; & arrFilename(i) & &quot;&quot;&quot;))&quot;
strFullStatement = strNextDocument & &quot; &quot; & &quot;AND&quot; & &quot; &quot; & strFullStatement
Next
'WScript.Echo Left(strFullStatement,len(strFullStatement) - 5) 'removes the last AND from the strFullStatement string
strFileExistsStatement = Left(strFullStatement,len(strFullStatement) - 5) 'removes the last AND from the strFullStatement string
WScript.Echo strFileExistsStatement
str1 = (objFSO.FileExists(&quot;AIX36009P01.doc&quot;)) AND (objFSO.FileExists(&quot;AIX36009.doc&quot;))
If strFileExistsStatement then
WScript.echo &quot;Files Exists&quot;
Else
WScript.echo &quot;Files dose not Exists&quot;
End If
/CODE
 
why not do this:

On Error Resume Next
Dim objFSO, objOpen, file
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objOpen = objFSO.OpenTextFile(&quot;C:\AIX36009_Req.txt&quot;,1)
Do until objOpen.AtEndOfStream
If objFSO.FileExists(objOpen.ReadLine()) = -1 Then wscript.echo &quot;File Exist&quot;
if objFSO.FileExists(objOpen.ReadLine()) = 0 Then wscript.echo &quot;File DOES NOT Exist&quot;
loop
 
I need to set the script up, to check to see if all of the files exists, if all files exits run another script else end.
 
This might be the half A$$ way of doing it, but it will work and save array code:
Dim objFSO, objOpen, file
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objOpen = objFSO.OpenTextFile(&quot;C:\AIX36009_Req.txt&quot;,1)
Do until objOpen.AtEndOfStream
file = objFSO.FileExists(objOpen.ReadLine())
if file = -1 Then exsist = True & vbCrLf & exsist
if file = 0 Then exsist = False & vbCrLf & exsist
Loop
If InStr(exsist,&quot;False&quot;) > 0 Then wscript.echo &quot;Not all Files Exist&quot;:wscript.quit
If InStr(exsist,&quot;False&quot;) = 0 Then wscript.echo &quot;All Files Exist&quot;:do the other code
 
Thank you for helping me. Can you explain the code for me I'm a beginner of programming
 
Sure Line by Line:
'Declare Variables
Dim objFSO, objOpen, file

'Create File System Object
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Open Text file that holds the files - must be full path ie:c:\winnt\note.ext
Set objOpen = objFSO.OpenTextFile(&quot;C:\AIX36009_Req.txt&quot;,1)

'do the following code until we reached the end of the document.
Do until objOpen.AtEndOfStream

'set file = the value of the FileExist method either 0 for not found or -1 for found
file = objFSO.FileExists(objOpen.ReadLine())

'if the file was found then add the value of &quot;True&quot; to the exsist var (which we also create onth file), enter a carraige return (vbCrLf) and concat the previous value of exist
if file = -1 Then exsist = True & vbCrLf & exsist

'if the file was NOT found then add the value of &quot;FALSE&quot; to the exsist var, enter a carraige return (vbCrLf) and concat the previous value of exist
if file = 0 Then exsist = False & vbCrLf & exsist

'move to the next line
Loop

'the whole file was read and exsist will be populated
'if anywhere in the exsist variable is the word &quot;False&quot; then kill the script and echo out, &quot;Not all file exist&quot;
If InStr(exsist,&quot;False&quot;) > 0 Then wscript.echo &quot;Not all Files Exist&quot;:wscript.quit

'if all the files were found and exsist does not cotain the word &quot;False&quot; at all then do the other code that you specify.
If InStr(exsist,&quot;False&quot;) = 0 Then wscript.echo &quot;All Files Exist&quot;:do the other code

let me know if you have any further questions
 
Thanks so much again for your help. If I have any questions I will ask you.
 
flybravo, FYI try this in your original script:
Code:
If Eval(strFileExistsStatement) Then


Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top