[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

File System Object - find a file on the hard drive

Posted on 2002-07-22
4
Medium Priority
?
181 Views
Last Modified: 2010-05-02
I wonder if anyone can help

I want to search for a file on my harddrive and then open and chage its contents. but i dont know where the file is. Any ideas?>
0
Comment
Question by:marksynnott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 20

Expert Comment

by:hes
ID: 7170116
Use this
Declare

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const MAX_PATH = 260
Private Const DRIVE_CDROM = 5
Private Const DRIVE_FIXED = 3

Call this

Private Function Find_File(FileName As String) As String
 Dim tempStr As String
 Dim Ret As Long
 Dim AllDrives As String
 Dim DriveArray
 Dim lErrCode As Long
 Dim Counter As Long
 Dim szValueName As String
 Dim sUNCName As String
 
   AllDrives = String(255, Chr$(0))
   Ret = GetLogicalDriveStrings(255, AllDrives)
   AllDrives = Replace(AllDrives, Chr$(0), "")
   AllDrives = Replace(AllDrives, "\", "\,")
   DriveArray = Split(AllDrives, ",")
 
 For Counter = 0 To UBound(DriveArray) - 1
 Ret = GetDriveType(DriveArray(Counter))
 
  If GetDriveType(DriveArray(Counter)) = DRIVE_FIXED Then
 
 
 
 
   'create a buffer string
   tempStr = String(MAX_PATH, 0)
   
   'returns 1 when successfull, 0 when failed
   Ret = SearchTreeForFile(DriveArray(Counter), FileName, tempStr)
   
   If Ret <> 0 Then
       Find_File = Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
       Exit Function
   End If
   
  End If
   
 Next Counter
 
 Find_File = "NOT FOUND"
End Function
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7170177
This works to locate any filename or file pattern:

'---
strFilename = "file to find.txt" ' patterns can also be used
Shell("command /c dir " & strFilename & " /s/b > C:\myfile.txt")
'---

(If using NT/2000/XP, replace "command" with "cmd".)

The result will be a file, myfile.txt, which contains all occurrences of the file you requested.  Once created, you can open the file and you'll see a list of the file(s) you were searching for.
0
 
LVL 5

Accepted Solution

by:
rpai earned 225 total points
ID: 7170183
Take a look here for different ways with which you can find a file:-
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q185476

Once you find the file, using one of the above mentioned mechanisms, you can open the file to modify the contents using the following lines of code:-

  Const ForReading = 1
  Const ForWriting = 2
  Const ForAppending = 8
  Dim fso As Object
  Dim f As Object

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile("c:\test.txt", ForWriting, True)
  f.Write "Text Modified"
  f.Close

  Set f = Nothing
  Set fso = Nothing
0
 

Author Comment

by:marksynnott
ID: 7687476
Thanjs a mill
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question