We help IT Professionals succeed at work.

Delete folders on a server by a script

DRRAM
DRRAM used Ask the Experts™
on
windows serveur 2008 R2
PLEASE I NEED A SCRIPT OR SOFTWARE THAT take the names of folders from the text file or Excel to delete the forlders.
or an other methode by commande line
thank you in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
Place the following in a DeleteFolders.cmd file.  It deletes all folders listed in the C:\Temp\folders.txt file.
@echo off
for /F %%f in (C:\temp\folders.txt) do rmdir /S /Q "%%f"

Open in new window

Bill PrewTest your restores, not your backups...
Top Expert 2016
Commented:
If your folder names in the text file could contain spaces then you will want to go with:
@echo off
for /F "tokens=*" %%f in (C:\temp\folders.txt) do rmdir /S /Q "%%f"

Open in new window

~bp
Commented:
If you have PowerShell, you could try:

Remove-Item -LiteralPath (Get-Content C:\Backup\df.txt)-Recurse -Force

where C:\Backup\df.txt is the file that contains the folder paths that you want to delete

Author

Commented:
EXCELLENT

Author

Commented:
bchallis
by: bchallisPosted on 2012-04-18 at 23:44:02ID: 37864426

I RUN this command :

""Remove-Item -LiteralPath (Get-Content C:\Backup\df.txt)-Recurse -Force""

but it doesn't delete the folder sharing and the owner is not specified

can I change the owner and remove the sharing and after that we can delete the folder.

thx