Sign in to follow this  
Followers 0
Erlend

Recursive search - filename - user profile directory

2 posts in this topic

Hello

I am writing a script to cleanup files from a old version of an application in the user profile folder in a terminal server environment.

i have found this script inn this thread:

Search ("C:\","advapi32.dll");replace with your search directory and file required

Func Search($current,$toFind)
    If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

            IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array delete it or whatever else you wanted to do with it here
                
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file, $toFind)
            
        EndIf
        
    WEnd
    FileClose($search)

EndFunc

What do i need to change add in this script to search and delete a file in the %userprofile% directory?

Thanks for any advice/examples :P

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello

I am writing a script to cleanup files from a old version of an application in the user profile folder in a terminal server environment.

i have found this script inn this thread:

CODE
Search ("C:\","advapi32.dll");replace with your search directory and file required

Func Search($current,$toFind)

If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)

Local $search = FileFindFirstFile($current & "\*.*")

While 1

Dim $file = FileFindNextFile($search)

If @error Or StringLen($file) < 1 Then ExitLoop

If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array delete it or whatever else you wanted to do with it here

EndIf

If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

Search($current & "\" & $file, $toFind)

EndIf

WEnd

FileClose($search)

EndFunc

What do i need to change add in this script to search and delete a file in the %userprofile% directory?

Thanks for any advice/examples :P

@UserProfileDir (re: "Macro Reference" in the Help file) Edited by Monamo

- 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