Jump to content

Delete all but a couple of files?


mist3r
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...