对路径"E:\System Volume Information"的访问被拒绝.

在进行目录遍历时遇到无法访问'E:\System Volume Information'的问题。该路径是系统隐藏的,通常不允许直接访问。通过编写IsSystemHidden方法,检查并过滤掉具有隐藏和系统属性的目录,从而避免访问被拒绝的错误。这种方法已验证有效。

    在遍历目录的时候出现“对路径"E:\System Volume Information"的访问被拒绝“这个问题。

百度了一下说是,某些路径是不可访问的,比如这个System Volume Information,每个磁盘下都有。


最后采用了,把隐藏文件过滤掉的方法:

private static bool IsSystemHidden(DirectoryInfo dirInfo)
        {
            if (dirInfo.Parent == null)
            {
                return false;
            }
            string attributes = dirInfo.Attributes.ToString();
            if (attributes.IndexOf("Hidden") > -1 && attributes.IndexOf("System") > -1)
            {
                return true;
            }
            return false;
        }

这个方法是别人写的,亲测可用。

2025/6/14 8:58:27 [1] ERROR System.Private.CoreLib Access to the path 'H:\System Volume Information' is denied. at System.IO.Enumeration.FileSystemEnumerator`1.CreateRelativeDirectoryHandle(ReadOnlySpan`1 relativePath, String fullPath) at System.IO.Enumeration.FileSystemEnumerator`1.MoveNext() at System.Linq.Enumerable.ExceptIterator[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer)+MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() at System.Linq.Enumerable.ChunkIterator[TSource](IEnumerable`1 source, Int32 size)+MoveNext() at System.Linq.Parallel.PartitionedDataSource`1.ContiguousChunkLazyEnumerator.MoveNext(T& currentElement, Int32& currentKey) at System.Linq.Parallel.ForAllOperator`1.ForAllEnumerator`1.MoveNext(TInput& currentElement, Int32& currentKey) at System.Linq.Parallel.ForAllSpoolingTask`2.SpoolingWork() at System.Linq.Parallel.SpoolingTaskBase.Work() at System.Linq.Parallel.QueryTask.BaseWork(Object unused) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) ---------------------------------------------------------------------------------------------------------------------- 2025/6/14 9:05:50 [1] ERROR SixLabors.ImageSharp Image cannot be loaded. Available decoders: - JPEG : JpegDecoder - BMP : BmpDecoder - PBM : PbmDecoder - TGA : TgaDecoder - TIFF : TiffDecoder - PNG : PngDecoder - Webp : WebpDecoder - GIF : GifDecoder at SixLabors.ImageSharp.Image.Load[TPixel](Configuration configuration, Stream stream, IImageFormat& format) at Masuit.Tools.Media.ImageSharpTransformer.TransformImage(Stream stream, Int32 width, Int32 height) at Masuit.Tools.Media.ImageHasher.DifferenceHash256(Stream sourceStream) at Masuit.Tools.Media.ImageHasher.DifferenceHash256(String pathToImage) at 以图搜图.Form1.btnSearch_Click(Object sender, EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
06-15
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值