Click to See Complete Forum and Search --> : Display file location
GinnyLee
December 22nd, 1999, 07:00 AM
I have a programme that searches for files and then displays their title and the last date they were modified. The thing I need to do is also display their location within the drives.
Any Ideas
Cheers
v
Chris Eastwood
December 22nd, 1999, 07:24 AM
When you say that you've already located the files, surely the information is already there in the file path (eg. c:\stuff\something\file.dat) ?
Or am I missing something here ?
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
GinnyLee
December 22nd, 1999, 08:29 AM
Chris
The programme I have is doing a recursive search through the C drive and finding documents of a certain type, *.doc,*.scr etc.
THe code I'm using is similar to whats at www.vb-world.net/ubb/Forum1/HTML/011939.html except that I'm using the input of a text box to search the C Drive.
Does this make things clearer, I've only been programming for 5 weeks so I'm not always certain what's going on!
Cheers
V
Chris Eastwood
December 22nd, 1999, 09:10 AM
I see.
I've copied the code from that posting and changed it for you - on your form, place a ListBox (List1) then copy in the following routine (or overwrite the one you have already there) :
private Sub LogFilesOfType(byval sType as string, optional byval sInitDir as string = "C:\")
Dim sSubFolder() as string
Dim iSubFolder as Long
Dim sDir as string
Dim bLogged as Boolean
on error resume next
If Right$(sType, 1) <> "," then sType = sType & ","
If Right$(sInitDir, 1) <> "\" then sInitDir = sInitDir & "\"
sDir = Dir(sInitDir & "*", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem + vbDirectory)
While len(sDir)
If (GetAttr(sInitDir & sDir) And vbDirectory) = vbDirectory then
If Left(sDir, 1) <> "." then
ReDim Preserve sSubFolder(iSubFolder)
sSubFolder(iSubFolder) = sDir
iSubFolder = iSubFolder + 1
End If
ElseIf InStr(sDir, ".") then
If InStr(sType, mid$(sDir, InStr(sDir, ".")) & ",") then
If Not bLogged then
'
' as we're not logging to notepad - ignore this
'
' sLog = sLog & vbCrLf & sInitDir & vbCrLf
bLogged = true
End If
'
' Add the full path/filename to the listbox - you could
' however do what you like with the full path/filename here
'
' Note that the 'sInitDir' value already has a '\' appended to it
'
List1.AddItem sInitDir & sDir
'
' don't bother logging this information to notepad
'
'sLog = sLog & " " & Left$(sDir & Space(50), 50) & Chr(9) & Format(FileDateTime(sInitDir & sDir), "HH:MM:SS AM/PM MM/DD/YYYY") & Chr(9) & FileLen(sInitDir & sDir) & vbCrLf
Caption = "Logged: " & Val(mid$(Caption, 9)) + 1
End If
End If
sDir = Dir
Wend
If iSubFolder then
for iSubFolder = 0 to UBound(sSubFolder)
Call LogFilesOfType(sType, sInitDir & sSubFolder(iSubFolder))
next
End If
End Sub
- Should help you out ...
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
GinnyLee
December 23rd, 1999, 02:45 AM
Chris
Thanks a millon
Virginia
Dr_Michael
December 23rd, 1999, 02:54 AM
There is no need to write million lines of code. There is also no need to reevent the wheel:
Go to the menu of vb:
Project-References
Search for Microsoft Scripting Runtime
Check on this to enable it.
Now go to your program, at the form load event (e.g.) and write these two lines:
Dim fso as FileSystemObject
set fso = new FileSystemObject
After this, type: "fso."
at the point you press the "." a drop down list will appear with some useful enough properties, methods etc...
Believe me, this gonna help you enough!!!
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.