简体   繁体   中英

Correct directory path in virtual machine

I've recently started using Windows 7 from my Mac on Parallels, and I'm having some issues finding the correct directory path for a file. In OS X, the path for a file named TestFile.txt is /Users/MyAccount/Documents/Visual Studio 2013/Projects/FTP Process/TestFile.txt. In Windows, however, the path is \\psf\\Home\\Documents\\Visual Studio 2013\\Projects\\FTP Process\\TestFile.txt.

I am trying to use the C# File.Exists() method with a string literal of this file path. I've tried using both of the above paths as the parameter of the method, and both return false when I expect one or the other to return true. Does anyone know what the correct string for this path would be? Thanks.

Differences in the path of special folders on various host operating systems are encapsulated via Environment.SpecialFolder .

You can get the actual path of a special folder with Environment.GetFolderPath .

Try something like

string documentsPath = 
    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

In your case, that should return

/Users/MyAccount/Documents/

under OS/X, and

\\psf\\Home\\Documents

under Windows (I'm guessing there will also be a drive letter under Windows, but not exactly sure how Parallels works).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM