Del command in command prompt
11,890
Use \
instead of /
as the path separator:
del %userprofile%\AppData\Roaming\MyFolder\myfile.txt
Comments
-
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 almost 9 yearsTry
del "%userprofile%/AppData/Roaming/MyFolder/myfile.txt"
-
newbieguy almost 9 yearsare quotes included?
-
barlop almost 9 yearsyeah 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 almost 9 yearsI think Windows allows / so maybe his problem is as in my comment.. not using quotes.
-
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 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 almost 9 yearswhat if the folder has space?
-
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 almost 9 yearsThat's correct. Windows command prompt only supports double quotes.
-
barlop almost 9 yearsIndeed the quotes enable the use of forward slash, pastebin.com/raw.php?i=xkxNuMxE well spotted @GregHewgill
-
barlop almost 9 yearsNo 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 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 almost 9 years@barlop ah that's right...thanks for the correction!
-
barlop almost 9 yearsI 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.