cunoc
asked on
Batch file Delete all files from a directory, except the 2 files ..
Hi,
These files are currently in C:\WINDOWS\Web\Wallpaper00 01
Pic0001.JPG
FUN000w.GIG
WHY0001.BMP
Do_Not_Delete_Me.txt
Do_Not_Remove_Me.txt
What I want to do is to Delete all files in C:\WINDOWS\Web\Wallpaper00 01
Pic0001.JPG
FUN000w.GIG
WHY0001.BMP
Except two files below, I don't want to delele ..
Do_Not_Delete_Me.txt
Do_Not_Remove_Me.DOC
Thanks
:://////////////////////// ////////// ////////// //////
::
:: Any other methods, that more better than the CODE below ... and
:: When it done the job, it should ECHO me that how many files has
:: been deleted from that directory and what files have left.
::
:://////////////////////// ////////// ////////// //////
@ECHO OFF
MD C:\WINDOWS\Web\Wallpaper00 02
XCOPY C:\WINDOWS\Web\Wallpaper00 01\*.* C:\WINDOWS\Web\Wallpaper00 02\
ECHO Y | DEL C:\WINDOWS\Web\Wallpaper00 01\*.*
COPY C:\WINDOWS\Web\Wallpaper00 02\Do_Not_ Delete_Me. txt C:\WINDOWS\Web\Wallpaper00 01\
COPY C:\WINDOWS\Web\Wallpaper00 02\Do_Not_ Delete_Me. DOC C:\WINDOWS\Web\Wallpaper00 01\
RD C:\WINDOWS\Web\Wallpaper00 02\
These files are currently in C:\WINDOWS\Web\Wallpaper00
Pic0001.JPG
FUN000w.GIG
WHY0001.BMP
Do_Not_Delete_Me.txt
Do_Not_Remove_Me.txt
What I want to do is to Delete all files in C:\WINDOWS\Web\Wallpaper00
Pic0001.JPG
FUN000w.GIG
WHY0001.BMP
Except two files below, I don't want to delele ..
Do_Not_Delete_Me.txt
Do_Not_Remove_Me.DOC
Thanks
::////////////////////////
::
:: Any other methods, that more better than the CODE below ... and
:: When it done the job, it should ECHO me that how many files has
:: been deleted from that directory and what files have left.
::
::////////////////////////
@ECHO OFF
MD C:\WINDOWS\Web\Wallpaper00
XCOPY C:\WINDOWS\Web\Wallpaper00
ECHO Y | DEL C:\WINDOWS\Web\Wallpaper00
COPY C:\WINDOWS\Web\Wallpaper00
COPY C:\WINDOWS\Web\Wallpaper00
RD C:\WINDOWS\Web\Wallpaper00
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi billprew:,
Here is errors I got when run the code..
@echo off
set BaseDir=c:\windows\web\wal lpaper0001
for /f "tokens=*" %%A in ('dir /a-d /b "%BaseDir%"') do (
if not "%%A" == "Do_Not_Delete_Me_0001.txt " (
if not "%%A" == "Do_Not_Remove_Me_0002.txt " (
del /q "%%~fA"
)
)
)
PAUSE ..
////////////////////////// ////////// /
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Ascen t.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Autum n.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Azul. jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Bliss .bmp
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Cryst al.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Follo w.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Frien d.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Home. jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Moon flower.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Peace .jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Power .jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Purpl e flower.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Radia nce.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Red moon desert.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Rippl e.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Stone henge.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Tulip s.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\TXT, Do_Not_Delete_Me_0001.t
xt
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\TXT, Do_Not_Delete_Me_0002.t
xt
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Vorte c space.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Wind. jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Windo ws XP.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\WinS_ DW_31.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\WinS_ DW_64.jpg
Press any key to continue . . .
Here is errors I got when run the code..
@echo off
set BaseDir=c:\windows\web\wal
for /f "tokens=*" %%A in ('dir /a-d /b "%BaseDir%"') do (
if not "%%A" == "Do_Not_Delete_Me_0001.txt
if not "%%A" == "Do_Not_Remove_Me_0002.txt
del /q "%%~fA"
)
)
)
PAUSE ..
//////////////////////////
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Ascen
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Autum
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Azul.
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Bliss
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Cryst
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Follo
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Frien
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Home.
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Moon flower.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Peace
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Power
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Purpl
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Radia
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Red moon desert.jpg
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Rippl
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Stone
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Tulip
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\TXT, Do_Not_Delete_Me_0001.t
xt
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\TXT, Do_Not_Delete_Me_0002.t
xt
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Vorte
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Wind.
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\Windo
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\WinS_
Could Not Find N:\USB, BACKUP, 0001\DOC0001\BAT0001\WinS_
Press any key to continue . . .
>> cunoc
That's rather strange.
What did you name the BAT file?
And do you have a mapped drive called N:, and does it have a folder "USB, BACKUP, 0001\DOC0001\BAT0001" in it?
~bp
That's rather strange.
What did you name the BAT file?
And do you have a mapped drive called N:, and does it have a folder "USB, BACKUP, 0001\DOC0001\BAT0001" in it?
~bp
ASKER
Hi Qlemo:
It works ... thanks
@ECHO OFF
cd /D C:\WINDOWS\Web\Wallpaper00 01
for %%F in ("Do_Not_Delete_Me_0001.tx t" "Do_Not_Delete_Me_0002.txt ") do attrib +h %%F
del /a:-h * /q /f
attrib -h *
PAUSE ..
It works ... thanks
@ECHO OFF
cd /D C:\WINDOWS\Web\Wallpaper00
for %%F in ("Do_Not_Delete_Me_0001.tx
del /a:-h * /q /f
attrib -h *
PAUSE ..
Now I'm confused. Both solutions work (proven), so both should get the points.
ASKER
Hi Qlemo:
Please accept my mistake, I was in a hurry and not pay attention, so how i am going to give the score to you as your work.. Please let me know,
Thanks
Please accept my mistake, I was in a hurry and not pay attention, so how i am going to give the score to you as your work.. Please let me know,
Thanks
Request Attention (red exclamation mark), with a reason like "want to reassign points" - that will create a request in Community Support. A Moderator will handle that by reopening the question ASAP, then you can close again.
ASKER
Hi,
It was my fault, so I would like "to reassign points to Qlemo", please accept my request. Thank you very much.
It was my fault, so I would like "to reassign points to Qlemo", please accept my request. Thank you very much.
ASKER
Hi Qlemo and billprew,
I am sorry for the mess, and hope this will resolved the issue.
Thanks the work you guys provided.
I am sorry for the mess, and hope this will resolved the issue.
Thanks the work you guys provided.
Open in new window