fd
fd copied to clipboard
Add --delete flag for file deletion on Windows
I have been here: #538, #585, #253.
On Windows, del
is used in CMD while Remove-Item
is used in PowerShell, both are built-in commands.
Therefore, there is no anything like a rm
executable on Windows and -X
or -x
will not work.
❯ fd -t f --change-older-than 4weeks -x del
[fd error]: Command not found: "del" "{N\\$%\\{N$%}VN4NSWE25%(P7)E94X.jpg"
[fd error]: Command not found: "del" "{N\\FX\\{NFXN6@5~Y014(G3GKQVG]G.jpg"
[fd error]: Command not found: "del" "{Q\\}U\\{Q}UETZ3~[[BYM}9H`{6SQ9.gif"
[fd error]: Command not found: "del" "{Q\\}S\\{Q}S]`]GVNE1YST`~847_6C.jpg"
[fd error]: Command not found: "del" "{Q\\~F\\{Q~FB6B%D6SJQC]W3ZCA~M6.jpg"
[fd error]: Command not found: "del" "{Q\\~8\\{Q~8{}@U{3G%UMN]GQ49~VG.png"
Currently I have something like this in order to simply delete a file, which is not desirable as it spawns a shell every time, and spawning processes on Windows is much slower than on Linux:
@echo off
echo %1
del %1
See also https://github.com/sharkdp/fd/pull/387.
Proper delete support requires post-order traversal which is not trivial to implement. However, considering the difficulty of doing this on Windows, I think I'm in favour of implementing --delete
.
In the meantime, you can make a wrapper script or batch file or something. Or use CMD/PowerShell's equivalent of sh -c ...
I would suggest adding such a workaround in README for the time being, it is quite confusing for new users:
@echo off
del %1
works for me.
Spawning a lot of processes isn't really the way to do some things on Windows as this is inherently much slower than Linux, and antivirus software such as Windows Defender further slow that down because they perform scanning when a process is spawned.
Linux users could also benefit from --delete
As discussed in #387, I think that a --delete
that only deals with files instead of directories is fine enough for the time being.
Ok, I'm happy to revisit this. The restriction to files could be a way to get rid of (some of) the edge cases discussed in #387.
In the meantime, you can make a wrapper script or batch file or something. Or use CMD/PowerShell's equivalent of
sh -c ...
The equivalent on Windows is -x cmd /c del
:
$ fd -g "*.orig" -x cmd /c del
if you are using powershell core you can use the following:
$ fd -g "*.orig" -x pwsh -c rm