Putting in X virtual disk of Windows PE 2.1 this script, it should delete all files and all directories of an NTFS partition in which there is the \Users directory except this directory and its subdirectories.

@echo off

for %%I in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
if exist %%I:\Users set DVDDrive=%%I else (
echo not exist the %%I:\Users directory.
goto :EOF)

pushd X:\Windows\System32

for /R %%f in (%DVDDrive%\) do (
if not "%%f" == "%DVDDrive%\Users" (attrib -rhsi *.* /s
del /s /q *.*)


Right or should I make some correction?


0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


I don't think you can delete non-empty sub-directories with DEL, can you? You need KILLDIR or something like that. Does that exist on PE? If not, I'm sure you could locate a free utility to do the same job.

Batch is completely the wrong "language" for this job, IMO, but I'm not familiar with the PE envirnoment so I'm not sure what your alternatives might be.

Looks like VBS can be made available http://www.msfn.org/board/lofiversion/index.php/t16552.html
Answered 06/22/2009 by: VBScab
Red Belt

Please log in to comment
You can delete subdirectories with Del.exe, you use Dell C:\AdminStudio Shared\*.* /S.

del /? gives you the other options available.

Answered 06/22/2009 by: Inabus
Second Degree Green Belt

Please log in to comment
DEL.EXE? Surely DEL is an internal command to the command processor, isn't it?

I just tested deleting the folder C:\Bin\Binn where the structure is C:\Bin\Binn\Binn\Binn and where the final folder contains 3 files. The command "ECHO Y|DEL C:\Bin\Binn /S" deleted the files but no folders. I used to do this stuff ad infinitum but the grey cells are now lost. I prefer script anyway. :)
Answered 06/22/2009 by: VBScab
Red Belt

Please log in to comment

cmd.exe /c RD "%ProgramFiles%\DUMMYFOLDER" /S /Q

This deletes the complete folder with subfolders and all files in there in silent mode...

Very effective...

Answered 08/03/2009 by: McRip
Orange Senior Belt

Please log in to comment