Questions tagged «getfiles»

8
当Directory.GetFiles()被拒绝访问时,忽略文件夹/文件
我正在尝试显示在所选目录(以及可选的任何子目录)中找到的所有文件的列表。我遇到的问题是,当GetFiles()方法遇到无法访问的文件夹时,它将引发异常,并且过程停止。 如何忽略此异常(并忽略受保护的文件夹/文件)并继续将可访问文件添加到列表中? try { if (cbSubFolders.Checked == false) { string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath); foreach (string fileName in files) ProcessFile(fileName); } else { string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories); foreach (string fileName in files) ProcessFile(fileName); } lblNumberOfFilesDisplay.Enabled = true; } catch (UnauthorizedAccessException) { } finally {}
73 c#  getfiles 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.