1.

Solve : How to find automatically the path for an appli ??

Answer»

Hi all!

I'm searching for a way to find automatically an apllication's path. What I have to do is to go inside the directory to launch a command, like :

cd C:\Program Files\VLC
vlc test.mpg -f

That works well, but what if it's not INSTALLED here ? To scan the whole disk is the only solution ?

Thanks in advance
rekamIs this your homework?

euhm, why ?

it's just because I'm trying to make a CD-ROM with an UI in which you'll have a little button and when you press it, it OPENS a specific program (which has to be installed before) with some specific option commands.

The thing is, I don't know where the program will be installed. It should be Program Files if nothing is changed during the install, but who knows...

Is there a way to do that ?Windows maintains a data store of all the file names on the system. A user can query this data store and extract all sorts of interesting information.

Code: [Select]strComputer = "."

Set WshShell = CreateObject("Wscript.Shell")
Set objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'vlc' and Extension = 'exe'")

For Each objFile in colFiles
WshShell.Run objFile.Name & " test.mpg -f"
Next

Save the script with a vbs extension and run from a command prompt as cscript scriptname.vbs

Good luck.
Quote

That works well, but what if it's not installed here ? To scan the whole disk is the only solution ?
i am afraid so. you can try the vbscript posted, or do the same with batch
Code: [Select]dir /B /S /A-D | findstr /I "yourfilename.ext"
You search like that?

An alternative would be (in a batch file):
Code: [Select]for /f %%I in ('dir "C:\file.txt" /s /b') do echo %%IYou can just use one % if you do it directly from Command Prompt.

If you want to just find the path (not to DISPLAY the filename), do this:
Code: [Select]for /f %%Iin ('dir "C:\file.txt" /s /b') do echo %%~dpIQuote from: Dark Blade on June 18, 2007, 05:27:30 PM
You search like that?
yes, that's my way of doing it when i have more search requirements that can't be accomplished just by cmd.exe's wildcard globbing.Okay, thanks!

for /f %%I in ('dir "C:\testasgi.txt" /s /b /p') do echo %%~dpI

I'm near the solution, now. I still have a problem with spaces. If the program is installed in "Program Files", the echo %%I display only "C:\Program" which is not very nice, at least from my point of VIEW...

Any idea ?Quote from: rekam on June 19, 2007, 01:47:03 AM
I'm near the solution, now. I still have a problem with spaces. If the program is installed in "Program Files", the echo %%I display only "C:\Program" which is not very nice, at least from my point of view...


You need to set a DELIMS switch appropriately to avoid the FOR command halting at the first space.

like this

for /f "delims==" %%I in ('dir "C:\testasgi.txt" /s /b /p') do echo %%~dpI

Type FOR /? at the prompt for more information.

Also, do you REALLY need the /p switch with DIR? This does not always work well in batch files. I can't see what use it is, unless it's left over from debugging. You're trying to find one file, right? You're never going to have a screenful of information.




Discussion

No Comment Found