hello friends,
i want to seach for a file in the computer. i dont know the exact location where it is. so the requirement is to search entire hard disk and get the path of the specified file.
after that we now save the path in a string variable.
now, we have to execute the appication with the path stored in the string.
may be using shell.
my problem is, i know only how to search for a file in a particular drive, but how do we perform a entire hard disk check?
and after we store the path in a string variable, say st.
if i execute with the code
Shell st,vbNormalFocus
or Shell " & st & ",vbNormalFocus
and in many ways i tried.
but i couldnt work out.
can any body please help me
13 3036
You looking to do a recursive search
There are many example of such searches on the web, I have written code in the past to do this, if you can wait 24hrs, I may be able to locate it for you.
As for the execution of the file once located and hopefully only 1 instance is located.
Normal Shell command should work in this instance. If not I like using Windows Scripting Objects, below are a couple options.
Assuming the search returns a true if the path (strPath) searched contains the file (defined for example as MyFile.exe) then
strFile = strPath & "\MyFile.exe"
To options come to mind (Assuming your string is strFile).
Dim objShell as Object
objShell = CreateObject ("WScript.Shell")
objShell.run(strFile) OR
Dim objShell, objCmd
objShell = CreateObject("WScript.Shell")
objCmd = objShell.Exec(strFile)
...
Shell st,vbNormalFocus
Assuming you have the path and (executable) filename in st, this should work. However, it might depend on what version of VB you're using.
...I have written code in the past to do this, if you can wait 24hrs, I may be able to locate it for you.
Yeah, I've done it once or twice, too.
This sounds like a good sample to add to the How-To series in the VB Articles area.
I got started good but trying to figure out if I want to put folder recursion in same sub or different one... - 'Constants needed if not using MS Scripting Runtime referece
-
'Const UnknownType=0
-
'Const Removable=1
-
'Const Fixed=2
-
'Const Remote=3
-
'Const CDRom=4
-
'Const RamDisk=5
-
Option Explicit
-
Private Sub Command1_Click()
-
'Call Search
-
Call SearchSystem(Fixed Or CDRom)
-
End Sub
-
-
Sub SearchSystem(DriveTypes)
-
'Replace As with 'As if not using MS Scripting Runtime reference
-
Dim fs As FileSystemObject
-
Dim dc As Drives
-
Dim oDrive As Drive
-
Set fs = CreateObject("Scripting.FileSystemObject")
-
Set dc = fs.Drives
-
-
Debug.Print "---"
-
-
For Each oDrive In dc
-
'Use bitwise expression to see if Drivetype is one of the Drivetypes we wish to search
-
If (oDrive.DriveType And DriveTypes) = oDrive.DriveType Then
-
'oDrive is a drive type we wish to search
-
Debug.Print oDrive.DriveLetter & " - " & oDrive.DriveType
-
End If
-
Next 'oDrive
-
Set fs = Nothing
-
Set dc = Nothing
-
End Sub
-
You looking to do a recursive search
There are many example of such searches on the web, I have written code in the past to do this, if you can wait 24hrs, I may be able to locate it for you.
yes friend, i can wait. or else give me the link when u find it, i will go through it.
one more thing i have not mentioned is currently i am using MsAccess2003, and vb6 code
thanq
Give this a try, You'll need to add the shell command yourself - 'Add MS Scripting Runtime reference
-
'Const UnknownType=0
-
'Const Removable=1
-
'Const Fixed=2
-
'Const Remote=3
-
'Const CDRom=4
-
'Const RamDisk=5
-
Option Explicit
-
Private Sub Command1_Click()
-
Dim mySearchPattern As String
-
mySearchPattern = "*.exe"
-
'look at constants above, use 'OR' + drive type to specify what type of drives to search. I added OR CDRom below
-
Call SearchSystem(Fixed Or CDRom, mySearchPattern)
-
End Sub
-
-
Sub SearchSystem(DriveTypes As Integer, _
-
FileSpec As String, _
-
Optional oFolder = Empty)
-
'Replace As with 'As if not using MS Scripting Runtime reference
-
Dim fs As FileSystemObject
-
Dim dc As Drives
-
Dim oDrive As Drive
-
Dim ofld As Folder
-
Dim file
-
Dim subdirs As New Collection
-
Dim subdir
-
-
Set fs = CreateObject("Scripting.FileSystemObject")
-
Set dc = fs.Drives
-
On Error GoTo errorhandler:
-
If oFolder <> "" Then
-
file = Dir$(oFolder & FileSpec)
-
Do While Len(file)
-
'File found
-
file = oFolder & file
-
-
'PUT YOUR CODE HERE TO EXECUTE FILE
-
Debug.Print file
-
-
'get next filename
-
file = Dir$()
-
Loop
-
-
file = Dir$(oFolder & "*.*", vbDirectory)
-
Do While Len(file)
-
' we've found a new directory
-
If file = "." Or file = ".." Then
-
' exclude "." and ".."
-
ElseIf (GetAttr(oFolder & file) And vbDirectory) = 0 Then
-
' ignore regular files
-
Else
-
' this is a directory, include the path in the collection
-
subdirs.Add oFolder & file
-
End If
-
' get next directory
-
file = Dir$()
-
Loop
-
-
' parse each subdirectory
-
For Each subdir In subdirs
-
Call SearchSystem(DriveTypes, FileSpec, subdir & "\")
-
Next
-
End If
-
-
If oFolder = "" Then
-
For Each oDrive In dc
-
'Use bitwise expression to see if Drivetype is one of the Drivetypes we wish to search
-
If (oDrive.DriveType And DriveTypes) = oDrive.DriveType Then
-
'oDrive is a drive type we wish to search
-
Debug.Print "Searching: " & oDrive.Path
-
If oDrive.IsReady Then Call SearchSystem(DriveTypes, FileSpec, oDrive.Path & "\")
-
End If
-
Next 'oDrive
-
Debug.Print "finished"
-
End If
-
Set fs = Nothing
-
Set dc = Nothing
-
Exit Sub
-
errorhandler:
-
If Err.Number = 75 Then
-
'Path/File access error (file locked for reading or doesn't exist?)
-
Debug.Print Err.Description
-
Resume Next
-
Else
-
Debug.Print Err.Description
-
MsgBox Err.Description & vbCrLf & "Hit CTRL+BREAK to debug or OK to quit."
-
End If
-
End Sub
Give this a try, You'll need to add the shell command yourself
i am very glad dear friend.
with the code given by you, i could perform the entire hard disk check.
thanq
now i got one more problem,
when i find the path of the executable file, i used the statement,
Shell file,vbNormalFocus
but it has given an error.
i am searching for a file with the name IFs.exe, it is located in
c:\Program Files\IFs\IFs.exe
since this path will be stored in variable file,
i executed the file with the code
Shell file,vbNormalFocus
it displayed a dialog box with a text box saying,
"Specify the location for IFs
IFs does not exists on c:\ Documents and settings\Ravi\My Documents\.
please specify the path"
actually my file location was c:\program files
but why it is searchig in Documents and Settings even though i specified the correct path by passing the variable "file" as
Shell file,vnNormalFocus
i am panic.
any how i am happy that i could perform the entire hard disk check.
Probably you only have the file name, and not the path, in your variable. I'd suggest you put a breakpoint on the Shell line, and examine the contents of the variable at that point.
Probably you only have the file name, and not the path, in your variable. I'd suggest you put a breakpoint on the Shell line, and examine the contents of the variable at that point.
i examined the content of the variable before executing the file.
it displayed the correct path with quotation marks as
"C:\Program Files\IFs\IFs.exe"
but when i try to execute it, it is giving error
i examined the content of the variable before executing the file.
it displayed the correct path with quotation marks as
"C:\Program Files\IFs\IFs.exe"
but when i try to execute it, it is giving error
Hm, that is odd.
What happens if you just paste this command into the immediate window... Shell "c:\Program Files\IFs\IFs.exe"
Here's another thought. Perhaps you need to change the current directory. So for example, you might try this in your code (hard-code it for now, just to try it out)... ChDir "c:\Program Files\IFs"
Shell "c:\Program Files\IFs\IFs.exe", vbNormalFocus
Here's another thought. Perhaps you need to change the current directory. So for example, you might try this in your code (hard-code it for now, just to try it out)... ChDir "c:\Program Files\IFs"
Shell "c:\Program Files\IFs\IFs.exe", vbNormalFocus
thanq friend, it really worked well.
thanq every body.
also can we chage the directory dynamically?
i tried
ChDir " & st & "
and
ChDir st
but they didnt work.
any how my problem was solved.
thanq every body
thanq friend, it really worked well.
thanq every body.
Excellent! Glad we could help. :)
As for the ChDir, certainly it can be done dynamically. It accepts a string argument. As is almost always the case in VB, this means you can use any expression which resolves to a string. For example, the following all produce the same result. - Dim strFullPath As String
-
Dim strPart1 As String, strPart2 As String
-
strFullPath = "C:\Temp\Temp2"
-
strPart1 = "Temp"
-
strPart2 = "p2"
-
' Version 1, a simple string literal...
-
ChDir "C:\Temp\Temp2"
-
' Version 2, a simple string variable...
-
ChDir strFullPath
-
' Version 3, all sorts of things concatenated...
-
ChDir "C:\" & strPart1 & "\Tem" & strPart2
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Abby Lee |
last post by:
My code does what I want (works unless there is a lot of
volume...works for this month cause not a lot of items marked paid
yet...) but the page times out for last month because there is just
so...
|
by: Julie |
last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB)
for a given string.
The files are unindexed and unsorted, and for the purposes of my immediate
requirements, can't...
|
by: Chung Leong |
last post by:
Here's a short tutorial on how to the OLE-DB extension to access
Windows Indexing Service. Impress your office-mates with a powerful
full-text search feature on your intranet. It's easier than you...
|
by: Chung Leong |
last post by:
Here's the rest of the tutorial I started earlier:
Aside from text within a document, Indexing Service let you search on
meta information stored in the files. For example, MusicArtist and...
|
by: Ray Muforosky |
last post by:
Hello all:
Task: I want to do file search, using the "conatining text" option from
a web page.
How do I search for a file on my local drive containing a certain
string, from a web page. That...
|
by: Ola K |
last post by:
Hi guys,
I wrote a script that works *almost* perfectly, and this lack of
perfection simply puzzles me.
I simply cannot point the whys, so any help on it will be appreciated.
I paste it all here,...
|
by: bb nicole |
last post by:
BElow is my php code for candidate search, it have 4 criteria which is academic background, functional experience, preferred location and languages ability. but it show yhe blanks page..
Emm, is it...
|
by: ravindarjobs |
last post by:
hi......
i am using ms access 2003,vb6
i have a form.
in that i have 2 buttons
1. start search
2 stop search
when i click the "start search" button the fucntion SearchSystem() is called,...
|
by: Sabine |
last post by:
Hi there,
I would need your help again.
I am using Dev Avish's API function "Search for a file"
http://www.mvps.org/access/api/api0006.htm
to find a file on my computer which works well. As...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |