Del command in command prompt

11,890

Use \ instead of / as the path separator:

del %userprofile%\AppData\Roaming\MyFolder\myfile.txt
Share:
11,890
newbieguy
Author by

newbieguy

I'm interested at programming

Updated on June 13, 2022

Comments

  • newbieguy
    newbieguy almost 2 years

    I want to, for example, delete a file in AppData/Roaming/MyFolder/myfile.txt.

    I use command prompt and typed this: del %userprofile%/AppData/Roaming/MyFolder/myfile.txt

    But then the command prompt said: Parameter format not correct - "ppData"

    Then I think again and used %appdata% and typed:del %appdata%/MyFolder/myfile.txt

    But the command prompt said: Invalid switch - "MyFolder"

    How to delete myfile.txt using %userprofile% or %appdata%? Is my syntax wrong?

    • barlop
      barlop almost 9 years
      Try del "%userprofile%/AppData/Roaming/MyFolder/myfile.txt"
    • newbieguy
      newbieguy almost 9 years
      are quotes included?
    • barlop
      barlop almost 9 years
      yeah I was including quotes, though my comment wasn't quite right. Quotes are fine but you should use backslash. Quotes may not be necessary but if there was a space anywhere e.g. in the expansion of %userprofile% (which is unlikely) or if you had a space in the filename or anywhere in the path, then you'd need quotes.
  • barlop
    barlop almost 9 years
    I think Windows allows / so maybe his problem is as in my comment.. not using quotes.
  • barlop
    barlop almost 9 years
    @GregHewgill ah you're right.. I remember somebody once said it did.. I see it does when clicking the orb and typing in the search box to bring up an explorer window. Though indeed, not in the command prompt
  • Greg Hewgill
    Greg Hewgill almost 9 years
    @barlop: / is usually permitted as a path separator when writing programs that directly call the Windows API functions. But even so, it's best to always use `\` on Windows.
  • newbieguy
    newbieguy almost 9 years
    what if the folder has space?
  • Greg Hewgill
    Greg Hewgill almost 9 years
    @cromix: Well then you'd probably also want to use quotes. (Using quotes may also allow the use of /, I'm not certain.)
  • Greg Hewgill
    Greg Hewgill almost 9 years
    That's correct. Windows command prompt only supports double quotes.
  • barlop
    barlop almost 9 years
    Indeed the quotes enable the use of forward slash, pastebin.com/raw.php?i=xkxNuMxE well spotted @GregHewgill
  • barlop
    barlop almost 9 years
    No that doesn't even work in the slightest pastebin.com/raw.php?i=aZntjX90 You are using forward slashes and single quotes neither of which are correct
  • barlop
    barlop almost 9 years
    @cromix You need to use a double quote rather than a single quote and escape it in your code.I suppose Try replacing each of the single quotes with \"
  • Lizzy
    Lizzy almost 9 years
    @barlop ah that's right...thanks for the correction!
  • barlop
    barlop almost 9 years
    I didn't make the edit and the edit that "ohbewise" made is not really a correction because you still have forward slashes there. Try the command yourself you'll get the same error as the questioner got. If I could downvote you 3 times I would. And a correct answer was posted before you, stating clearly to do backslash instead of forward slash. So even correcting your answer would be pointless because it just repeats what others have already said better in the same thread, before you.