Go Back   Tech Support Forum > Microsoft Support > Windows XP Support

User Tag List

Batch File To delete Specific Folders

This is a discussion on Batch File To delete Specific Folders within the Windows XP Support forums, part of the Tech Support Forum category. Hi friends, Please guide me how to create a batch file to fit this scenario, "I have a Folder Named


Closed Thread
 
Thread Tools Search this Thread
Old 11-17-2010, 03:14 AM   #1
Registered Member
 
Join Date: Nov 2010
Posts: 1
OS: XP(SP2), Windows 7



Hi friends,

Please guide me how to create a batch file to fit this scenario,

"I have a Folder Named Addons which has 110 Folders which themselves has many sub folders and files of differnet extentions for eg(C:\Program Files\OpenERP\Addons). In this I have to leave around 15 decided Folders and their contents in Addons. I have delete the remaining Folder and its contents. The Number of folders and Their Names may vary every time depending on the Computer.

I have to use batch file both in Windows XP and Windows 7.

I am new one to create batch files. Please guide me.
Rk_Raj is offline  
Sponsored Links
Advertisement
 
Old 11-17-2010, 04:39 AM   #2
CCT
Helper
 
CCT's Avatar
 
Join Date: Mar 2009
Posts: 4,126
OS: abacus



Let's say of the 110 folders in the AddOns directory and 10 are dedicated (not to be deleted).

Are those dedicated folder names constant? (they are never changed?)
CCT is offline  
Old 11-17-2010, 05:14 AM   #3
TSF Enthusiast
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,645
OS: All of the above



Are the 15 folders you want to keep in the root of your main folder?

IF so you can put the folders you don't want to delete into a text file. One folder name on each line.

Then you could pipe the output of the dir command to the findstr command and do an inverse search based on the contents of the file with the directories you do not want to delete.

Code:
pushd "C:\Program Files\OpenERP\Addons"
For /F "tokens=*" %%I In ('dir /AD /b ^|Findstr /I /V /G:donotdelete.txt') Do rd /s /q "%%I"
Squashman is offline  
Sponsored Links
Advertisement
 
Old 11-17-2010, 08:12 AM   #4
CCT
Helper
 
CCT's Avatar
 
Join Date: Mar 2009
Posts: 4,126
OS: abacus



Rk_Raj, since you are learning, I threw together the following to show how it can be done (maybe not as smooth as some but at least with some tutorial value).

You can copy and paste to Notepad then save as Something.bat.

cd\

Rem changes to root directory

cd\"Program Files\TempAddOns\"

Rem changes to a Temporary folder (you will have to create) in C:\programs that will store your keepable files/folders from Addons

Rmdir Ded1 /s /q

Rem deletes the Temporay storage folder in preparation for writing new data (this was a Safety copy)

Mkdir Ded1

Rem creates a replacement, empty, Temporary storage folder (you will have to add names and more lines like this here Mkdir Ded2, etc)

cd\"Program Files\OpenERP\AddOns\"

Rem changes to the Main data folder

xcopy "Ded1\*.*" "C:\Program Files\TempAddOns\Ded1\*.*" /s /e

Rem copies the Dedicated files/folders from a specific folder to the Temporary folder that matches

cd\"Program Files\OpenERP\"

Rem Goes up one level in the Main data path in preparation for file deletion

Rmdir AddOns /s /q

Rem deletes ALL files/folders in the Main data folder by deleting the folder

Mkdir AddOns

Rem creates a new Main data folder

cd\"Program Files\OpenERP\AddOns\"

Rem goes down one level in the Main data path

Mkdir Ded1

Rem creates a new Dedicated data folder matching your old name (you will have to add names and more lines like this here)

xcopy "C:\Program Files\TempAddOns\Ded1\*.*" "C:\Program Files\OpenERP\AddOns\Ded1\*.*" /s /e

Rem copies the Temporary folder files/folders back to the Main folder matching entry
CCT is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2
Powered by vBadvanced CMPS v3.2.3


All times are GMT -7. The time now is 04:41 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.1.0 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Copyright 2001 - 2018, Tech Support Forum

Windows 10 - Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts