问题
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...???
UPDATE
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"?
UPDATE 2
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);
}
UPDATE 3
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
UPDATE 4
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?
UPDATE 5
With this code:
string clientVer = HHSUtils.GetFileVersion(@"\Application\sscs\HHSetup.exe");
...I still get an empty string from that call, followed by a Win32Exception.
回答1:
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);
}
回答2:
Yes, in CE, the root of all storage is \
. See here for details: Understanding the File System Architecture in Windows CE .NET. In particular:
The Windows CE .NET file system is a flexible modular design that allows for custom file systems, filters, and a variety of different block device types. The file systems and all file-related APIs are managed by the FileSys.exe process. This module implements the object store and Storage Manager (we'll look into the object store in a little bit) and unifies all of the file systems into a single system under one root, "\". In Windows CE .NET, all files and file systems exist in a single namespace starting from "\" as the root. All files are identified with a unique path from the root in a hierarchal tree.
Devices can be mounted to the root filesystem, and the mount names are identified in the registry, under HKEY_LOCAL_MACHINE\System\StorageManager\Profiles
.
来源:https://stackoverflow.com/questions/22181093/how-does-one-designate-the-root-of-a-handheld-device