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!

loop to find missing filenumbers (files)

Status
Not open for further replies.

DefinityCorporation

IS-IT--Management
Sep 26, 2002
22
US
I need a script to verify files exist. Preferably just give a list of missing file numbers. Files are 10000001.pdf ~ 99999999.pdf. Here is what I came up with (total newbie) this doesnt work and is probably garbage. HELP! I can't count 99 million files!!! Thanks!
'-----------------------------------------------------------
Dim fso, f1, N
Set N=10000000
start
Do While N <99999999
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("c:\"" & N"".pdf")
If fso.FileExists(f1) Then
Response.Write "File found: " & f1.name
Else If
Response.Write "***MISSING FILE: " & f1.name
End If
Set N = N+1
loop
'---------------------------------------------------------
 
I'm pretty new to VBS scripting too, as my past was CMD and KIX scripting, but I think I've found a few issues in the code. Maybe this will get you started until someone smarter than I can step in and finish up the cure. I'll take each item one at a time.

1.)I don't believe you need to instantiate the FSO object everytime the loop runs. Instantiate it first, then use it in the loop.

2.) You souldn't need to GetFile to see if it exists, just set f1 to the path and file name and use it in the fso.FileExisit method. Also, the & N & should not be in quotes.

3.) Response.Write doens't point to any file to write to. Additionally, do you want it to write both found files and missing?

So I'm thinking it should look something a little closer to this:

Dim fso, f1, N, file
Set N=10000000
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso_OpenTextFile("C:\MyLog.txt", 8, TRUE)
start
Do While N <99999999
Set f1 = "c:\" & N & ".pdf"
If fso.FileExists(f1) Then file.WriteLine "File found: " & f1
Else file.WriteLine "***MISSING FILE: " & f1
End If
Set N = N+1
loop
Set file = Nothing
Set fso = Nothing

Also, I'm not sure the "Start" is needed. I hope this gets you closer to a solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top