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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if file exists

Status
Not open for further replies.

lpb71

Technical User
Mar 10, 2004
57
GB
Below is a snippet of my vbscript that check to see if a file(s) exists via a variable and writes to a log file if the file(s) exists. If I enter the parameters as per the labels below in the fso line, it works fine, however if I enter them as below is does not seem to pickup from the labels. How can I get my script to use the labels I have created.

Thanks


Set objFSO = CreateObject("Scripting.FileSystemObject")
set LogFile=objfso.opentextfile("dvdlog.txt",2,True)

branchid = InputBox("Enter Branch Number")
dvddrive = InputBox("Enter Drive Letter for DVD Writer")

Label = "b" + (branchid) + "sr01"
File1 = " c:\temp\b" + (branchid) + "sr01.0"
File2 = " c:\temp\b" + (branchid) + "sr01.1"
File3 = " C:\temp\b" + (branchid) + "sr01.2"
FileA = (dvddrive) + ":\b" + (branchid) + "sr01.0"
FileB = (dvddrive) + ":\b" + (branchid) + "sr01.1"
FileC = (dvddrive) + ":\b" + (branchid) + "sr01.2"
wscript.echo "File2 =" & chr(34) & FILE2 & chr(34)

If objFSO.FileExists (FILE3) then
logfile.writeLine ("3 Files Exist")
wscript.quit
end if

If objFSO.FileExists (FILE2) then
logfile.writeLine ("2 Files Exist")
wscript.quit
end if

If objFSO.FileExists (FILE1) then
logfile.writeLine ("1 Files Exist")
wscript.quit
end if

 
Take out wscript.quit inside the if-end if. Quit means quit and stop proceeding to next test.
 
I need my script to quit after it writes to the log file, otherwise it will find the 2nd file and write that 2 files exist. The script should only quit if it meets the if statement. Shouldn't it?
 
The file path has to be exact, whitespace counted. Your File1... etc have a leading space. Why?
 
Typo, didn't notice that - many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top