Page 1 of 1
Need help deleting files within a folder.
Posted: 13 Sep 2011 04:18
by Exouxas
Hi guys/gals!
As the title says, i need help deleting files within a folder, hope any of you can help.
Heres the statements i tried:
Code: Select all
erase /Q /A %CD%\Files\ -:%CD%\Files\Menu.bat -:%CD%\Files\firsttime.txt
Code: Select all
erase /Q /A Files\ -:Files\Menu.bat -:Files\firsttime.txt
Code: Select all
erase /Q /A \Files\ -:\Files\Menu.bat -:\Files\firsttime.txt
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 05:39
by Bob D
You can use the same command syntax in the DIR command to see a list of files that qualify for your criteria.
You could also turn off the /Q for debugging. You didn't say what your problem was.
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 11:08
by Exouxas
It says: "file not found"
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 14:36
by Bob D
You appear to be trying to exclude files by using the - (not). The - is to negate the attribute(s).
to see all files but no folders in a folder
or this works too
shows no directories and all text files beginning with s.
I can't see how to do an exclude based on filename. When you are ready to do the real thing add the /Q and change the DIR to DEL or ERASE
edit: Further checking indicates you can't use a list of files. The filenames after the first are ignored.
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 15:13
by Exouxas
So theres no way of deleting everything in a folder except two specific files?
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 15:20
by Exouxas
Got a genious idea of how to do this now.
copy/move the two files to the previous directory, remove the folder they were in, then make a new folder and put the files in there
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 16:04
by trebor68
If you want to delete the files "menu.bat" and "firsttime.txt" please use the following code:
Code: Select all
erase /Q Files\Menu.bat Files\firsttime.txt
If the sign "-:" in a later version than Windows XP have a meaning, then I do not know.
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 16:20
by Exouxas
i wanted to exclude them FYI
Re: Need help deleting files within a folder.
Posted: 13 Sep 2011 16:26
by Bob D
You could use the ATTRIB command to set all attributes to +A (or anything else that is convenient) then set the two files to something else (+R) and then do a delete based on not R
Code: Select all
attrib -R -A -S -H -I *.* > nul
attrib +R fileA > nul
attrib +R fileB > nul
del /q /a-r