Jump to content

Folder search and delete


ttoscan
 Share

Recommended Posts

I am trying to uninstall an application, then install a newer version of it. When I uninstall it using my autoit script, it uninstalls fine, but leaves a folder for the application in each user's profile\application data folder under documents and settings. This will prevent the newer version from installing correctly.

I am trying to add to my script to search for the folder, then delete it, but not knowing each user's profile name.

Can anybody give me any ideas. I first tried to use comspec, but cannot get it to delete a folder. It works great for searching for a specific file and deleteing it.

Thanks.

Tom T.

Link to comment
Share on other sites

If you only need it for the current user then use the @AppDataDir macro to get the Current users Application Data folder. If you need it for the All Users Application Data folder then @AppDataCommonDir.

For locating the Application Data folder for several users you would start by locating the Documents and settings folder

$ds_Fldr = @HomeDrive & "\Documents and Settings\" and then work it out from there.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Can anybody give me any ideas.

Perhaps this code example may help you

; Target folder to remove
Const $FOLDERNAME = 'Microsoft'

; Change current directory
If FileChangeDir(@UserProfileDir & '\..') Then
    ConsoleWrite('WorkingDir = ' & @WorkingDir & @CRLF); Test purpose only
    ; Create a search handle
    $handle_search = FileFindFirstFile("*")
    If $handle_search <> -1 Then
        While 1
            ; Get the next file/folder
            $folder_profile = FileFindNextFile($handle_search)
            If @error Then ExitLoop
            ; Check that it is a folder
            if StringInStr(FileGetAttrib($folder_profile), 'D') Then
                ; Skip these profiles
                Switch $folder_profile
                    Case 'All Users', 'Default User', 'LocalService', 'NetworkService'
                        ContinueLoop
                EndSwitch
                ; Build a relative path to the target folder
                $folder_target = $folder_profile & '\Application Data\' & $FOLDERNAME
                If FileExists($folder_target) Then
                    ; Remove the target folder
                    ConsoleWrite('Target = ' & $folder_target & @CRLF); Test purpose only
                    ;DirRemove($folder_target, 1); Uncomment for folder removal
                EndIf
            EndIf
        WEnd
        FileClose($handle_search)
    EndIf
EndIf

Tested output looks ok

WorkingDir = C:\Documents and Settings

Target = Michael\Application Data\Microsoft

You can set $FOLDERNAME to your target folder, remove the ConsoleWrite() functions and uncomment the the DirRemove() when satisfied.

:D

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...