Jump to content

Recommended Posts

Posted

Hey,

I've been reading the help file looking at the file commands and trying to peice together how i'd use them to basically delete everything in a folder except a couple of folders.

Its basically going to remove all user profiles except "administrator, all users, default user"

I take it loop and look for matches.

IF $filename doesnt equal "administrator"

FileDelete ( "$filename )

Im just struggling mainly on how to actually start the loop and get the filenames.

Please help, any advice is certainitly appreciated.

Thanks! :P

Posted

A small change to the helpfile example of FileFindFirstFile() may help.

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    ; Restart the loop if select folders not found
    If  $file <> "Administrator" And _
        $file <> "All Users" And _
        $file <> "Default User" Then
        ContinueLoop
    EndIf
    ; Check if is directory and remove if it is
    If StringInStr(FileGetAttrib($file), "D") Then
        DirRemove($file, 1)
    EndIf
;~     MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

You would stil need to FileChangeDir() or use fullpaths to the Homepath as the example is relative only.

Posted

Aaah excellent! :P I love it. Im still working on it as it's actually deleting the administrator folders as well. I think i'll figure it out.

Oh 1 last thing. the "AND _" i take it that means.. AND IF $file.."

Posted (edited)

The underscore ( _ ) is just a way of splitting one line of code into multiple lines, making it more readable. These three lines:

If  $file <> "Administrator" And _
    $file <> "All Users" And _
    $file <> "Default User" Then
Edited by Sokko
Posted

Aah! Thanks ever so much u 2. I really really appreciate your help. Ive finally done it and its just a life saver tbh.

The Microsoft DelProf doesnt do a very good job of removing half the stuff so this should work :P Thanks again

Posted

Beware of deleting some of the system (background) user (LocalService, NetworkService, etc) profiles.

Note that you may not have access to all the folders (by design). Use the CACLS utility wisely. :P

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
×
×
  • Create New...