简体   繁体   中英

How to include the current user's path on a file?

I have a file in a folder on a user's local drive. I want to reference it by just the last few folders, how do i do that? example:

string filePath = \\folder\file.txt; 

Use "GetParent"

string path = Directory.GetCurrentDirectory(); //current path
string path1 = Directory.GetParent(path).ToString(); //parent of current path
string path2 = Directory.GetParent(path1).ToString(); //parent..
string path3 = Directory.GetParent(path2).ToString(); //parent..

Optimize it if you really want to use it. It just shows how it 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