Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Exouxas
- Posts: 34
- Joined: 01 Sep 2011 12:52
#1
Post
by Exouxas » 13 Sep 2011 04:18
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
-
Bob D
- Posts: 20
- Joined: 07 Sep 2011 18:32
- Location: Eastern Australia
#2
Post
by Bob D » 13 Sep 2011 05:39
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.
-
Bob D
- Posts: 20
- Joined: 07 Sep 2011 18:32
- Location: Eastern Australia
#4
Post
by Bob D » 13 Sep 2011 14:36
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.
-
Exouxas
- Posts: 34
- Joined: 01 Sep 2011 12:52
#5
Post
by Exouxas » 13 Sep 2011 15:13
So theres no way of deleting everything in a folder except two specific files?
-
Exouxas
- Posts: 34
- Joined: 01 Sep 2011 12:52
#6
Post
by Exouxas » 13 Sep 2011 15:20
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
-
trebor68
- Posts: 146
- Joined: 01 Jul 2011 08:47
#7
Post
by trebor68 » 13 Sep 2011 16:04
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.
-
Exouxas
- Posts: 34
- Joined: 01 Sep 2011 12:52
#8
Post
by Exouxas » 13 Sep 2011 16:20
i wanted to exclude them FYI
-
Bob D
- Posts: 20
- Joined: 07 Sep 2011 18:32
- Location: Eastern Australia
#9
Post
by Bob D » 13 Sep 2011 16:26
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