Search code examples
cmdcommand-prompt

How to include a "." in the rmdir to remove a folder that has a dot on the name on command prompt


Im trying to filter the folders that i want to remove:

for /d %%G in ("C:\Users\andre\Desktop\Users\:*.") do rd /s /q "%%~G"

There is two folders in \Users

 abc
 abc.dfg

I just need to delete the "abc.dfg" and keep the "abc" How can I add the "."(dot) to filter only the "abc.dfg" directory?


Solution

  • Due to the way wildcards are working in cmd (*= "zero or more" and ? = "zero or one"), each wildcard-approach is doomed from the start.

    where treats wildcards differently (* = "one or more" and ? = "exactly one"), but works for files only, so you can't use it here.

    That leaves you with checking if there is (not) an extension:

    for /d %%G in (abc*) do if not "%%~xG" == "" ECHO rd /s /q "%%~G"
    

    (remove the ECHO if the output looks ok)