c# - Why is File.Move not working as expected? -


i trying move files rootfolderpath destinationpath

try {     string rootfolderpath = @"d:\log_siteq\";     if (!directory.exists(path.combine(@"d:\log_takaya\" + combobox1.selecteditem.tostring())))     {         system.io.directory.createdirectory(path.combine(@"d:\log_takaya\" + combobox1.selecteditem.tostring()));     }       string destinationpath = path.combine(@"d:\log_takaya\" + combobox1.selecteditem.tostring() );     string filetypes = @"*.*";     string[] filelist = system.io.directory.getfiles(rootfolderpath, filetypes);     foreach (string file in filelist)     {         string ext = path.getextension(file);         string destination = path.combine(destinationpath,file);                          file.move( file,destination);         messagebox.show(file);         messagebox.show(destination);     } } catch(exception ex) {     messagebox.show(ex.tostring()); } 

apparently messagebox.show(file); shows me root folder path ( normal) messagebox.show(destination); showing me same thing.

what gives? moves file root folder in same folder.am not getting something?

you combining destinationpath complete file path of file:

string destination = path.combine(destinationpath, file); 

which overwrite destination original file path (because "c:\desitnation\c:\source\filename.txt" isn't valid path).

instead, need file name this:

string destination = path.combine(destinationpath, path.getfilename(file)); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -