Sign in to follow this  
Followers 0
jero1987

Question on Folder Deletion

4 posts in this topic

Hey i had a real quick question...

I want to write a quick script that deletes all folders and subfolders but the ones that i specify.

For example i have a folder that contains, Folder1 Folder2 Folder3 and Folder4.

I have the variables...

$Folder1 = "Folder1"

$Folder2 = "Folder2"

Now i want to delete everything in that directory except for $folder1 and $folder2.

Thanks.

Share this post


Link to post
Share on other sites



What have you tried so far? You may simply do a move of the folders to a different area, then delete everything in the folder in question. once done, move the folders back.

Well see im trying to delete windows accounts on a lab install. So i cant move out the admin account. I need to clean out all other accounts but the ones specified.

Share this post


Link to post
Share on other sites

Hey i had a real quick question...

I want to write a quick script that deletes all folders and subfolders but the ones that i specify.

For example i have a folder that contains, Folder1 Folder2 Folder3 and Folder4.

I have the variables...

$Folder1 = "Folder1"

$Folder2 = "Folder2"

Now i want to delete everything in that directory except for $folder1 and $folder2.

Thanks.

Quick and dirty example:

#include <File.au3>

$FolderRoot = @ScriptDir & "\Test\" 
$Folder1 = "Folder1" 
$Folder2 = "Folder2" 

$AllFolders = _FileListToArray($FolderRoot, "*", 2)
If Not @error Then
    For $i = 1 To $AllFolders[0]
        If $AllFolders[$i] <> $Folder1 And $AllFolders[$i] <> $Folder2 Then
            DirRemove($FolderRoot & $AllFolders[$i], 1)
        EndIf
    Next
EndIf

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0