简体   繁体   中英

How can I provide relative path to command line arguments in start option in C#

I have one directory folder where we are getting 100 files per day.

My program picks the files from the IN folder and puts them in the Out folder after processing them.

I am getting the issue that when I am giving the exact location in

Project > Properties > DEBUG > START OPTION > COMMAND LINE ARGUMENTS

(ie "C:\\Data\\IN\\File.txt") then the program executes successfully and finds the file, but when I provide the Location like "C:\\Data\\IN" it is not picking any file and is throwing the exception

Could not find file 'C:\\Data\\In'. InnerException is Null.

The IN folder is getting 100 different files daily. How can I solve this problem?

You need to use the Directory.GetFiles() static class to get a list of files to process. The Microsoft Documentation has a useful example.

https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx

"C:\\Data\\IN" is not a relative path, it is an absolute path to the directory containing the files. You can get the files like this from an absolute directory path:

string[] files = Directory.GetFiles(@"C:\Data\IN", "*.txt");

If you only know the path of the directory relative to the EXE you can get the absolute path like this:

string dir = Path.Combine(Application.StartupPath, @"Data\IN");

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