Delete both: hidden and normal files with cmd
Asked Answered
P

3

9

Following line recursively deletes only HIDDEN files with .mta extension

del /S /A:H <folder_name> *.mta

What I want to do is, to delete both: hidden and normal files with .mta extension. How to do it?

Pronunciation answered 11/12, 2011 at 12:1 Comment(0)
D
17

Use /a on its own: del /s /a *.mta

eg:

C:\temp\z>attrib *
A   H        C:\temp\z\hidden
A            C:\temp\z\normal
C:\temp\z>del /s /a *

C:\temp\z\*, Are you sure (Y/N)? y
Deleted file - C:\temp\z\hidden
Deleted file - C:\temp\z\normal
Doig answered 11/12, 2011 at 12:7 Comment(2)
No - it just got deleted. However you want somethng like "for /f %F in ('dir /b/a *.mta') do if not exist "%~nF" echo %F" to obtain a list of files suitable for cleanup.Doig
#8464416Pronunciation
R
0
for /f %F in ('dir %cd%\* /s /b /a:-D ^| findstr /vile ".cab .exe .bat"') do del /a "%F"

I took most of this form another site and combined it with my knowledge of dos and basically, you open a command prompt in windows change the directory to the root of the the one you want to remove the files from, then it scans (S) the directory via (B) retrieving all files.
The .cab, .exe and .bat files extensions will not be presented to the variable %F thus never deleted.
do delete all file archive types in %F. You can add /a:H for hidden files only or what ever archive bit you want to include or not include suing a - in front of the Archive switch.

Raina answered 18/9, 2016 at 5:10 Comment(0)
Y
0

If you want to delete a hidden folder using cmd, then you have to use cmd as administrator privilege, then locate the directory in which you have the folder for deletion, and then use this command:

C:\> rmdir /S /Q "directory name"
Yettie answered 22/4, 2024 at 6:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.