C# getting full path of an input file in win XP -
i wrote simple console tool reads file , writes out. intend drag , drop files , out pops output in same directory input file.
all of testing works, , when call command-line, comes out expected. however, when tried dragging , dropping in explorer, no files created.
i did search through system , found dumped @ documents , settings under user folder, , when printed out full path that's said.
which weird. wouldn't path.getfullpath
return absolute path of input file? instead looks combined user directory path input's filename.
edit: here's code. feel i've made logic error somewhere can't seem see it.
filename = system.io.path.getfilename(args[i]); abspath = path.getfullpath(filename); dirpath = path.getdirectoryname(abspath); .... console.writeline(dirpath);
path.getfullpath should return absolute path of path string pass in.
path.getfilename(string path) returns filename , extension of file pass in. example, system.io.path.getfilename("c:\somedirectory\test.txt");
return "test.txt". you'll want use path.getdirectoryname path of input file, so:
string inputdirectory = system.io.path.getdirectoryname(args[i]);
alternately, can use fileinfo class retrieve bunch more information input file. example:
// assuming args[i] = "c:\somedirectory\test.txt" fileinfo inputfile = new fileinfo(args[i]); string inputdirectory = inputfile.directoryname; // "c:\somedirectory" string inputfilename = inputfile.name; // "test.txt" string fullinputfile = inputfile.fullname; // "c:\somedirectory\test.txt"
Comments
Post a Comment