如何在计算机中搜索文件并执行 [英] how to search for a file in the computer and execute

查看:80
本文介绍了如何在计算机中搜索文件并执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,


我想在计算机中查找文件。我不知道它的确切位置。因此要求是搜索整个硬盘并获取指定文件的路径。


之后我们现在将路径保存在字符串变量中。


现在,我们必须使用存储在字符串中的路径执行应用程序。


可能正在使用shell。



我的问题是,我只知道如何搜索特定驱动器中的文件,但是我们如何执行整个硬盘检查?


并且在我们存储路径之后在字符串变量中,比如st。


如果我执行代码


Shell st,vbNormalFocus


或Shell" &安培;邮票; ,vbNormalFocus


,在很多方面我都试过了。

但我无法解决。


可以请帮助我

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

推荐答案

你想做一个递归搜索

有很多这样的例子在网上搜索,我已经编写了过去的代码来做这件事,如果你可以等24小时,我也许可以找到它。


至于执行文件一旦找到并希望只找到一个实例。


普通Shell命令应该在这个实例中起作用。如果不是我喜欢使用Windows Scripting Objects,下面是几个选项。


假设搜索的路径(strPath)包含文件(例如定义为MyFile),则搜索返回true。 exe)然后

strFile = strPath& " \ MyFile.exe"

想到选项(假设你的字符串是strFile)。

将objShell作为对象调暗

objShell = CreateObject(" WScript.Shell")

objShell.run(strFile)
OR

Dim objShell,objCmd

objShell = CreateObject(" WScript.Shell")

objCmd = objShell.Exec(strFile)
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
...
Shell st,vbNormalFocus



假设你在st中有路径和(可执行)文件名,这应该工作。但是,它可能取决于你正在使用的VB版本。

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.



...我已经编写了过去的代码这样做,如果你可以等24小时,我可以找到它。
...I have written code in the past to do this, if you can wait 24hrs, I may be able to locate it for you.



是的,我已经完成了一两次。


这听起来像是一个很好的样本添加到VB文章区域中的操作方法系列。

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.


这篇关于如何在计算机中搜索文件并执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆