问题标签 [system.io.fileinfo]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 复制后删除文件会杀死应用程序
我在使用FileInfo.Delete()
或Directory.Delete(path, true)
复制文件夹时发现了一个非常奇怪的错误。
问题:
- 递归复制包含许多文件和一些子文件夹的文件夹
- 尝试递归删除原文件夹
- 恰好在文件夹内的第三个文件上,应用程序将崩溃而不会抛出
Exception
- 它并不总是同一个文件,因为前两个被正常删除,第三个失败。(如果我再试一次,第一个将是最后一个失败的,并且会成功删除)
再生产:
在WPF
应用程序中,具有以下方法的按钮会导致崩溃(稍后我将尝试在控制台应用程序中重现):
递归复制或删除:(
我知道Directory.Delete(path, true)
存在,但它也失败了,我创建了递归删除来检查发生了什么)
重要细节:
- 这是一个“错误再现”代码。原来的应用比较大,复制和删除之间有与用户的交互。这种“复制和删除”不是应用程序的正常流程,但用户可以通过调用应用程序的两个不同命令来做到这一点
- 在用户单击复制和单击删除之间,应用程序完全响应有一个时间间隔。复制操作在用户可以做任何其他事情之前完成。
- 如果只调用delete命令不会出现问题,如果先有副本就会出现问题
- 我尝试释放资源,但似乎无法用于
FileInfo
andDirectoryInfo
。无论如何,我尝试尽快将所有内容设置为 null ,但没有成功。 - 没有
Exception
抛出,应用程序完全崩溃 - 所有文件都可以访问,没有一个是只读的
- 视窗 10
- 使用 C# 的 WPF 应用程序
- Visual Studio 2017 调试(问题发生在步进与否)
powershell - System.IO.FileInfo and Relative Paths
I was wondering if someone could help me understand why does System.IO.FileInfo
behaves differently on Windows than on Linux when handling relative paths.
Example
- On Linux
- On Windows
EDIT
To clarify on the above, there is no difference on how System.IO.FileInfo
handles relative paths on Windows or Linux. The issue is related to [System.IO.Directory]::GetCurrentDirectory()
not being updated by Push-Location
or Set-Location
.
A simple example:
And assuming this is a expected behavior, what would be an optimal way to approach our param(...)
blocks on scripts and functions to accept both cases (absolute and relative). I used to type constraint the path parameter to System.IO.FileInfo
but now I can see it is clearly wrong.
This is what I came across, but I'm wondering if there is a better way.
I believe Split-Path -IsAbsolute
will also bring problems if working with Network Paths, please correct me if I'm wrong.
The following should be able to handle:
- UNC Paths
- Work on Windows and Linux
- Be efficient
- Handle Relative Paths
Starting from the base that $Path
is valid thanks to the ValidateScript attribute
, we only need to determine if the path we are dealing with is UNC, Relative or Absolute.
UNC paths must always be fully qualified. They can include relative directory segments (. and ..), but these must be part of a fully qualified path. You can use relative paths only by mapping a UNC path to a drive letter.
We can assume a UNC path must always start with \\
, so this condition should suffice to determine if $Path
will be manipulated or not:
Lastly, in the begin
block, updating the environment's current directory each time our script or function runs with:
By doing so, ([System.IO.FileInfo]$Path).FullName
should give us the absolute path of our parameter, be it UNC, Relative or Absolute.
vb.net - GetFiles 非常慢 vb.NET
我需要处理大量文件并通过一组目录和子目录搜索并从找到的目录中获取文件。这很容易使用一个简单的目录,但是当搜索一千个目录时,程序会变慢到爬行。我听说过使用 enumeratefiles 但我不知道如何解决这个问题。谢谢你。
我应该如何处理这个?
谢谢你。