i have folder these files:
- file1.exe
- file2.dll
i want check exists extraneous files in folder. example if create examplefile.exe in folder must give me error, there must files listed above. i've created needed files string:
string[] only_these_files = { "file1.exe", "file2.dll" }; now need search extraneous files, how to? immediately.
i'm tried code, don't know how check it.
string[] only_these_files = { "image1.png", "image2.png", "image3.png", "image4.png", "image5.png" }; string[] fileentries = directory.getfiles(@"c:\users\dewagg\desktop\test\"); list<string> badfiles = new list<string>(); foreach (string filename in fileentries) if (!only_these_files.contains(filename)) { badfiles.add(filename); }
it's not rocket science: you:
hashset<string> allowedfiles = new hashset<string>( stringcomparer.ordinalignorecase ) { "file1.exe" , "file2.dll" , }; directoryinfo directory = new directoryinfo( @"c:\foo\bar" ) ; bool containsnonallowedfiles = directory .enumeratefiles( @"c\foo\bar" ) .any( fi => !allowedfiles.contains( fi.name ) ) ; bool containsallallowedfiles = allowedfiles .all( fn => directory.enumeratefiles( fn ).any() ) ;
Comments
Post a Comment