12

特定のファイルのフルパスを取得するにはどうすればよいですか?

たとえば、私は提供します:

string filename = @"test.txt";

結果は次のようになります。

Full File Path = C:\Windows\ABC\Test\test.txt
4

9 に答える 9

14

試す

string fileName = "test.txt";
FileInfo f = new FileInfo(fileName);
string fullname = f.FullName;
于 2012-11-01T11:19:31.893 に答える
9

Path.GetFullPath() を使用します。

http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx

これにより、完全なパス情報が返されます。

于 2012-11-01T12:31:22.703 に答える
8

あなたが使用することができます:

string path = Path.GetFullPath(FileName);

その言及されたファイルのフルパスを返します。

于 2014-12-20T05:43:04.103 に答える
7

Directory.GetCurrentDirectory

string dirpath = Directory.GetCurrentDirectory();

Prepend this dirpath to the filename to get the complete path.

As @Dan Puzey indicated in the comments, it would be better to use Path.Combine

Path.Combine(Directory.GetCurrentDirectory(), filename)
于 2012-11-01T11:17:56.213 に答える
4

私は自分の答えが遅すぎることを知っていますが、それは他の人に役立つかもしれませ

Void Main()
{
string filename = @"test.txt";
string filePath= AppDomain.CurrentDomain.BaseDirectory + filename ;
Console.WriteLine(filePath);
}
于 2016-03-10T05:29:06.340 に答える
2

try..

Server.MapPath(FileUpload1.FileName);
于 2012-11-01T11:17:16.127 に答える
1

試す:

string fileName = @"test.txt";
    string currentDirectory = Directory.GetCurrentDirectory();
    string[] fullFilePath = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories);

現在のディレクトリとそのサブディレクトリにあるそのようなすべてのファイルのフル パスを文字列配列 fullFilePath に返します。ファイルが 1 つしか存在しない場合は、「fullFileName[0]」になります。

于 2015-07-03T09:57:43.640 に答える
1
private const string BulkSetPriceFile = "test.txt";
...
var fullname = Path.GetFullPath(BulkSetPriceFile);
于 2014-03-17T13:50:11.373 に答える
0

現在のパスを取得できます。

string AssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();

幸運を!

于 2016-07-01T16:45:47.500 に答える