Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --delete flag for file deletion on Windows #871

Open
kmod-midori opened this issue Nov 1, 2021 · 7 comments
Open

Add --delete flag for file deletion on Windows #871

kmod-midori opened this issue Nov 1, 2021 · 7 comments

Comments

@kmod-midori
Copy link

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
@tavianator
Copy link
Collaborator

See also #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 ...

@kmod-midori
Copy link
Author

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.

@daniejstriata
Copy link

Linux users could also benefit from --delete

@kmod-midori
Copy link
Author

As discussed in #387, I think that a --delete that only deals with files instead of directories is fine enough for the time being.

@sharkdp
Copy link
Owner

sharkdp commented Nov 10, 2021

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.

@neandrake
Copy link

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

@saljic
Copy link

saljic commented Aug 7, 2023

if you are using powershell core you can use the following:

$ fd -g "*.orig" -x pwsh -c rm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants