Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all files in a directory using batch? [closed]

I have a very simple query. I have a folder "x" on my desktop (Windows 7), and I want to write a Batch Program to delete all files in it. (all extensions) This is what I've come up with:

cd c:\users\admin\desktop\x\
del *.*

but, when I open it, the console still asks for Human input (Y/N). What can I do to bypass this?

like image 800
user2591717 Avatar asked Jul 17 '13 14:07

user2591717


2 Answers

Always use the explicit path so a flaw does not delete the current folder, whatever that may be at the time.

All visible files, silently

del "c:\users\admin\desktop\x\*.*?"

All visible files, silently using /q

del /q "c:\users\admin\desktop\x\*.*"

All visible files, including subdirectories, silently

del /s /q "c:\users\admin\desktop\x\*.*"

type del /? for full info.

like image 125
foxidrive Avatar answered Nov 12 '22 12:11

foxidrive


It's dangerous, but

del *?*

or

del ?*?

should delete as required.

like image 33
Magoo Avatar answered Nov 12 '22 13:11

Magoo