I need to recursively search a handheld device for any files anywhere on the device that follow a certain pattern (such as "Platypus.XML").
To pass the root of the device to my directory traversal method, do I pass "\" or something else?
In Windows Explorer, the device is "J:\" - but I know that can't work, because it won't be mapped to J for everyone.
The device's full name in Windows Explorer is something like:
Duckbill (\\LEXINGTON\dev\Xmen\Miguel\Installs) (J:)
...but similarly, each person's device will have a different name, so that won't work.
So is the root folder designated with "\" or is there some method I can call to get that designator, something like Environment.SpecialFolder.Startup or...???
More specifically to my situation, if Windows Explorer says the folder in question is "Computer\Goliath's Device\Application\ccr", is the following what I need to programmatically designate that folder: "\Application\ccr"?
The following code results in a FileNotFound Exception and then a crash of the .exe on the handheld device:
string clientVer = HHSUtils.GetFileVersion(@"\\Platypus.exe");
public static string GetFileVersion(string filePath)
{
const int VERSION_DEPTH = 4;
var version = NativeFile.GetFileInfo(filePath);
return version.Version.ToString(VERSION_DEPTH);
}
With the following:
string serNum = User.getSerialNo();
string clientVer = DuckbillUtils.GetFileVersion("\\Application\\ccr\\Platypus.exe");
MessageBox.Show(string.Format("serial num == {0}; clientVer == {1}", serNum, clientVer));
...I get:
serialnum == ; clientVer == ; Win32Exception
whereas with the following:
string clientVer = DuckbillUtils.GetFileVersion(@"\\Application\ccr\Platypus.exe");
(other lines of code identical; verbatim string the only difference)
...I get:
serialnum == ; clientVer == ; FileNotFoundException
I found some good info here, and based on code from there:
string modulePath = this.GetType().Assembly.GetModules()[0].FullyQualifiedName;
...this is what it showed me for my .exe:
"\Program Files\HHS\HHS.exe"
...I then tried to examine a "cousin" exe at (in a different subfolder, but share the same grandparent folder):
@"\\Program Files\\LocateNLaunch\\LocateNLaunch.exe"
...but that gave me nothing from the GetFileVersion() method.
Anyway, the file I really want to examine (for its version info) is in, not a folder per se, but what for lack of knowledge will call a "subdevice" (I don't know what the terminology is, but in Windows Explorer the device is divided into "subdevices" or "superfolders" which have folders beneath them). How does one indicate/designate THAT is what you want to access? My .exe is in one "subdevice" and the .exe whose version info I need to read (and possibly replace) is in another "subdevice"...
If this is unclear, here's a scream shot:
So how can I point my code to that file (HHSetup.exe) beneath the Application subdevice\sscs folder?
With this code:
string clientVer = HHSUtils.GetFileVersion(@"\Application\sscs\HHSetup.exe");
...I still get an empty string from that call, followed by a Win32Exception.
The device name is irrelevant, it's purely a Explorer Shell Extension trick. On the device itself, the root is always \
. All paths must be fully qualified from that root.
I'd recommend doing some testing before getting the native version info. Something like:
if(!File.Exists(path))
{
// don't try, report an error or whatever
}
else
{
var version = GetFileInfo(path);
}
or
var fi = new FileInfo(path);
if(!fi.Exists)
{
// don't try, report an error or whatever
}
else
{
var version = GetFileInfo(fi.FullName);
}