Search code examples
windowsbatch-filecmd

The System cannot find the file specified error while deleting folder


Hi can some one suggest me how to delete below folder(abc) using a batch file?

%UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc

I tried like RD %UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc /Q /S

But it is not deleting and when I execute the same command in command line it is giving a message like "The System cannot find the file specified" even though it is exists.

Any solution?


Solution

  • At a command line run:

    ECHO %UserProfile%
    

    What does it return?

    Open that directory in Windows Explorer and double check that a folder called AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc exists in it.

    I'm thinking that maybe it doesn't exist, and the folder you're looking at that you said does exist, is in a directory with a root that is different from %UserProfile%.

    Update

    Open a new command window by doing the following, which ensures that it's in Administrator mode.

    On a Shortcut to a command window, Right Click > Properties > Shortcut > Advanced and check the "Run As Administrator" checkbox, and click OK twice. Then run the command prompt via the shortcut. You'll know it worked if it looks like this, with the word "Administrator" in the title, see screenshot below. Then try running your RD command again.

    enter image description here