How do I delete all symlinks and only all symlinks from a folder with a batch file/script?

The folder is c:\wamp\www, and this is what I've tried:

Content files delete.cmd

for /f "delims=" %%D in ("dir /a:l /s /b c:\wamp\www") do (
rmdir c:\wamp\www\%%D

But my code does not work.


Treat the symlink (even folder symlinks) as the file they are and not a folder:

FOR /F "usebackq delims=" %a IN (`DIR /a:l /s /b "."`) DO del "%a"

If you're working with hardlinks, that's a bit harder, to detect use something like

`find "." -links +1`

in your for loop to find the hardlinks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.