Jump to content

Delete all files and folders except some specific folders


Recommended Posts

Guest FLaplante
Posted

Hi...

i'm looking create a script file that can delete all files and folders

except some specific folders.

 

For exemple... i have a folder called TEMPORARY... then in this

folder, my users can put there files or folders they want for

temporary usage. Once a week, i need to delete all the content of the

TEMPORARY folder except one folder : FTP_XEROX (used for the xerox

scanner).

 

How can i delete all the files and folder in the TEMPORARY and make an

exception for the FTP_XEROX folder ??

 

Thanks in advance for you answers!

 

--

Fred Laplante

Sintra inc.

  • Replies 1
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: Delete all files and folders except some specific folders

 

 

"FLaplante" <flaplante@gmail.com> wrote in message

news:2cb3e13f-ba01-4820-bb6c-a6cbb5192ec5@s13g2000prd.googlegroups.com...

> Hi...

> i'm looking create a script file that can delete all files and folders

> except some specific folders.

>

> For exemple... i have a folder called TEMPORARY... then in this

> folder, my users can put there files or folders they want for

> temporary usage. Once a week, i need to delete all the content of the

> TEMPORARY folder except one folder : FTP_XEROX (used for the xerox

> scanner).

>

> How can i delete all the files and folder in the TEMPORARY and make an

> exception for the FTP_XEROX folder ??

>

> Thanks in advance for you answers!

>

> --

> Fred Laplante

> Sintra inc.

 

Try this batch file:

 

@echo off

set Target=My Data

set Exception=FTP_XEROX

 

pushd "%Target%"

if /i not "%CD%"=="%Target%" goto :eof

 

echo The curren folder is "%CD%".

echo del /q "%target%\*.*

for /d %%a in (*.*) do (

if /i not "%%a"=="%Exception%" echo rd /s /q "%%a"

)

popd

 

The word "echo" occurs four times in this batch file.

To activate the batch file, remove occurrence #3 and #4.


×
×
  • Create New...