Jump to content

Recommended Posts

Posted

Probably a simple one but I cannot figure it out without using external files to support it ..

I would like to delete any file in a given directory or subdirectory with a given extention eg .test

I can do this no probs for the current directory as FileFindFirstFile and Next file only work within the current directory but attempting to scan inside subdirectories seems a bit tricky ....

any help appreciated ..

Posted

Probably a simple one but I cannot figure it out without using external files to support it ..

I would like to delete any file in a given directory or subdirectory with a given extention eg .test

I can do this no probs for the current directory as FileFindFirstFile and Next file only work within the current directory but attempting to scan inside subdirectories seems a bit tricky ....

any help appreciated ..

You're right. It's a bit tricky :whistle: I prepared you that script. Just change the names of variables to your case. And rest should be good ;)

Dim $PATH_TO_DELETE = "C:\MyTest"
Dim $DirData, $DirOutputOnce

Dim $drivers_drive = StringMid($PATH_TO_DELETE, 1, 3)
$DirOutput = Run(@ComSpec & " /c DIR /A:D /S " & $PATH_TO_DELETE, '', @SW_HIDE, 2)
While 1
    $DirData = StdoutRead($DirOutput)
    If @error Then ExitLoop
    If $DirData Then
        $DirOutputOnce &= $DirData
    Else
        Sleep(10)
    EndIf
WEnd
; Remove spaces from output
$DirOutputOnce = StringStripWS($DirOutputOnce, 3)
; Split output into array
$DirSplit = StringSplit($DirOutputOnce, @CRLF, 1)

For $i = 1 To $DirSplit[0]
    If StringInStr($DirSplit[$i], $PATH_TO_DELETE) Then
        $somestring = StringSplit($DirSplit[$i], $drivers_drive, 1)
        If $somestring[0] = 2 Then ; Testing amount of elements in array, if more then 2 Exits
            If StringInStr($drivers_drive & $somestring[2], $PATH_TO_DELETE) Then ; Making sure that Drivers path exists in string
                $drivers_directory = $drivers_drive & $somestring[2]
                $search_txt = $drivers_directory & "\*.test"
                $h_Search = FileFindFirstFile($search_txt)
                If $h_Search <> - 1 Then
                    While 1
                        $file = FileFindNextFile($h_Search) 
                        If @error Then ExitLoop
                        MsgBox(0, "File:", $drivers_directory & "\" & $file)
                        FileDelete($drivers_directory & "\" & $file)
                    WEnd
                EndIf
                FileClose($h_Search)
            EndIf
        EndIf
    EndIf
Next

My little company: Evotec (PL version: Evotec)

Posted

You're right. It's a bit tricky :whistle:...

Nice code. Since you used ComSpec, then I will too.

$path = 'C:\MyTest\*.ext'
Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE)
;FileFindFirstFile()
;FileFindNextFile()

Oh, do not need the commented code. ;)

Posted

Thanks Madboy - looks good - I am having problems with the below code

Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE, 2 ) - Removed the ,2

$DirOutputOnce &= $DirData - removed the extra &

StdoutRead($DirOutput) - Where is this function

Nice code. Since you used ComSpec, then I will too.

$path = 'C:\MyTest\*.ext'
Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE)
;FileFindFirstFile()
;FileFindNextFile()

Oh, do not need the commented code. :whistle:

Posted

Thanks Madboy - looks good - I am having problems with the below code

Run(@ComSpec & ' /c del /f /s /q "' & $path & '"', '', @SW_HIDE, 2 ) - Removed the ,2

$DirOutputOnce &= $DirData - removed the extra &

StdoutRead($DirOutput) - Where is this function

Mhz :whistle:) Nice code, mine was based on something else i just converted it from my other program.

bourny: You have to use either My version or Mhz version. It seems you're trying to use both. If you're using mine don't remove & as it's needed there. I don't realy know what you're trying to change!! And why?

My little company: Evotec (PL version: Evotec)

Posted

Thanks to both ...

Madboy - I copied your script out and the Scite script checker failed the script on my pointed out areas ...

I have tried MHz 3 liner version seperatly and works no probs.

Thanks to you both for your efforts and the answer to my question ..

Bourny

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
  • Recently Browsing   0 members

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