| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 97496 | 2009-02-18 00:15:00 | Delete all folders except some | jwil1 (65) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 748879 | 2009-02-18 00:15:00 | I want to delete all the user profiles on several machines via a batch file. Is there a way to tell the batch file to delete all folders in C:\Documents and Settings EXCEPT All Users, Default User and Administrator?? TIA :) |
jwil1 (65) | ||
| 748880 | 2009-02-18 03:24:00 | Not easily using DOS commands, but this script would accomplish it: //************************************************** ************************ function FolderDeleter() { try { this.excludedFolders = new ActiveXObject( " Scripting.Dictionary " ); this.excludedFolders.add( " C:\\Documents and Settings\\Administrator " , true); this.excludedFolders.add( " C:\\Documents and Settings\\All Users " , true); this.excludedFolders.add( " C:\\Documents and Settings\\Default User " , true); this.fileSystemObject = new ActiveXObject( " Scripting.FileSystemObject " ); this.rootFolder = this.fileSystemObject.GetFolder( " C:\\Documents and Settings " ); } catch (exception) { WScript.Echo( " Error: " ); WScript.Echo(exception.message); WScript.Quit(1); } } //************************************************** ************************ function FolderDeleter.prototype.deleteSubFolders() { try { var subFoldersEnum = new Enumerator(this.rootFolder.SubFolders); while (!subFoldersEnum.atEnd()) { var item = subFoldersEnum.item(); if (this.excludedFolders.exists(item.Path)) { WScript.Echo( " excluding: " + item.Path); } else { WScript.Echo( " deleting: " + item.Path); try { this.fileSystemObject.DeleteFolder(item.Path, true) } catch (exception) { WScript.Echo( " Error when deleting: " + item.Path); WScript.Echo(exception.message); } } subFoldersEnum.moveNext(); } } catch (exception) { WScript.Echo( " Error: " ); WScript.Echo(exception.number); WScript.Echo(exception.descrption); WScript.Quit(1); } } //************************************************** ************************ function main() { var folderDeleter = new FolderDeleter(); folderDeleter.deleteSubFolders(); WScript.Echo( " done. " ); } //************************************************** ************************ main(); And to run the script (pays to run it with Administrator rights), save the above into a file named " FolderDeleter.js " : cscript [path-to-where-you-saved-it]\FolderDeleter.js |
dyewitness (9398) | ||
| 1 | |||||