.net - vb.net exclude specific file names from copying? -
how exclude specific file being copied during copy process. want exclude being copied example name.xml, adress.xml , data.xml
here code msdn use:
dim backupdir string = application.startuppath & "\backup" dim sourcedir string = application.startuppath if not directory.exists(backupdir) io.directory.createdirectory(backupdir) end if try dim xmllist string() = directory.getfiles(sourcedir, "*.xml") each f string in xmllist 'remove path file name. dim fname string = f.substring(sourcedir.length + 1) file.copy(path.combine(sourcedir, fname), path.combine(backupdir, fname), true) next catch copyerror ioexception console.writeline(copyerror.message) end try
prepare list(of string) names of files don't want copy, use path.getfilename
extract filename full file names returned directory.getfiles(). before executing copy check if file contained in list of excludedfiles
dim excludefiles = new list(of string)() excludedfiles.add("file1.xml") excludedfiles.add("file2.xml") excludedfiles.add("file3.xml") each f string in xmllist 'remove path file name. dim fname string = path.getfilename(f) if excludedfiles.indexof("file3.xml", _ stringcomparison.currentcultureignorecase) <> -1 file.copy(f, path.combine(backupdir, fname), true) end if next
Comments
Post a Comment