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

Search for file except this one. Can't loop. Pls Help.

Status
Not open for further replies.

bigracefan

Programmer
Apr 2, 2002
304
US
I've got a file that has hung up and I can't seem to get past it. How do I search a dirctory for all files except this one. Below is the code I have. It never checks for anything but this file since it's that last file (alphbetically).


'Find newest file
dirname = Dir("n:\Share\Hpcheck\tests\line" & MachineName & "\", vbDirectory)

For icount = 1 To dirskip + 2
FileName = Dir
Next
Dim test


Do Until FileName = &quot;&quot; Or UCase(Right(newfile, 3)) = &quot;TXT&quot; 'Or UCase(FileName) <> &quot;1674700742.TXT&quot;
If UCase(Right(FileName, 3)) = &quot;TXT&quot; Then
If UCase(FileName) <> &quot;1674700742.TXT&quot; Then
If UCase(Right(FileName, 3)) = &quot;TXT&quot; Then
myPath = &quot;n:\Share\Hpcheck\tests\line&quot; & MachineName & &quot;\&quot; & FileName
If DateDiff(&quot;s&quot;, CDate(FileDateTime(myPath)), Now) > 200 Then
newfile = FileName
End If
Else
FileName = Dir()
End If
FileName = Dir()
End If


End If
Loop
 
The code implies there can be files with extensions of other than .TXT, this seems to be where the problem lies. From my understanding of what you are doing Ive tried to simplify the code might need a bit more work its getting late -
Do Until FileName = &quot;&quot;
If UCase(Right(FileName, 3)) = &quot;TXT&quot; And UCase(FileName) <> &quot;1674700742.TXT&quot; Then
myPath = &quot;n:\Share\Hpcheck\tests\line&quot; & MachineName & &quot;\&quot; & FileName
If DateDiff(&quot;s&quot;, CDate(FileDateTime(myPath)), Now) > 200 Then
newfile = FileName
Exit Do
End If
FileName = Dir()
Loop
 
'Find newest file
Here is were you've been starting your directory reading.
dirname = Dir(&quot;n:\Share\Hpcheck\tests\line&quot; & MachineName & &quot;\&quot;, vbDirectory)

This section was reading all the filenames before it got to the DO LOOP. So it would have been putting you at the last Filename in the directory as long as dirskip+2 was more than the number of files in the directory. What is it supposed to do?
If you left it in you would have to restart the DIR command after the FOR LOOP.

' For icount = 1 To dirskip + 2
' FileName = Dir This line will read every file name and do nothing with them.
' Next
Here is were you've been finishing your directory reading before you've done anything with the file names.-

Dim test

Do Until FileName = &quot;&quot; Or UCase(Right(newfile, 3)) = &quot;TXT&quot; 'Or UCase(FileName) <> &quot;1674700742.TXT&quot;
If UCase(Right(FileName, 3)) = &quot;TXT&quot; Then
If UCase(FileName) <> &quot;1674700742.TXT&quot; Then
If UCase(Right(FileName, 3)) = &quot;TXT&quot; Then
myPath = &quot;n:\Share\Hpcheck\tests\line&quot; & MachineName & &quot;\&quot; & FileName
If DateDiff(&quot;s&quot;, CDate(FileDateTime(myPath)), Now) > 200 Then
newfile = FileName
End If
Else
FileName = Dir()
End If
FileName = Dir()
End If


End If
Loop




________________________________________________________________________________
You can't put a square peg in a round hole without a lot of force.
If at first you don't succeed get a bigger hammer. - Steve 2003.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top