简体   繁体   English

如何在文件中包含当前用户的路径?

[英]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" 使用“ 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. 它只是说明它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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