简体   繁体   中英

Why the Path.Combine is not combining the path and file?

I have this code:

string log_file_name = @"\logger.txt";
            string logger_file_to_read = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
            string LoggerFile = Path.Combine(logger_file_to_read, log_file_name);

I used a breakpoint and i see that : logger_file_to_read contain:

C:\\Users\\bout0_000\\AppData\\Local\\Diagnostic_Tool_Blue_Screen\\Diagnostic Tool Blue Screen\\log

And that log_file_name contain:

\\logger.txt

But then i see that LoggerFile contain only the file name: \\logger.txt Without the directory.

Whay is that ?

It's right there in the documentation :

If path2 does not include a root (for example, if path2 does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. If path2 includes a root, path2 is returned.

将反斜杠放在文件名中,如下所示:

string log_file_name = "logger.txt";

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