c# - Copy file into different folder directory name -
i create code copy don't know how combine copy code if filename not in jpeg
,bmp
,png
or gif
copy different folder name(c:\dump
) if filename extension exists file copy (c:\destionation
).
public static void copyfile( string[] args ) { copyfolder( @"c:\source", @"c:\destination" ); console.readline(); } static public void processdirectory(directoryinfo directory) { foreach (fileinfo file in directory.enumeratefiles("*.jpg,*.bmp,*.png,*.gif,*.jpeg")) { //how combin process directory info copy folder statement// } } static public void copyfolder( string sourcedir, string destfolder ) { if (!directory.exists( destfolder )) directory.createdirectory( destfolder ); string[] files = directory.getfiles( sourcedir ); foreach (string file in files) { string name = path.getfilename( file ); string dest = path.combine( destfolder, name ); file.copy( file, dest); } }
you can compare extension of files with:
path.getextension(myfilepath);
for example, can add in code:
foreach (string file in files) { string name = path.getfilename( file ); string dest = path.combine( destfolder, name ); if(path.getextension(myfilepath) != "jpg" && path.getextension(myfilepath) != "bmp" && path.getextension(myfilepath) != "png" && path.getextension(myfilepath) != "gif" && path.getextension(myfilepath) != "jpeg" ){ file.copy( file, dest); } }
you can have reference in path.getextension method documentation.
Comments
Post a Comment