Jump to content

Open any file and check if extansion matched then remove if not ?


Recommended Posts

Nop i cant add an exception, not that smart yet :)

I guess i need to change my name back to where it was "Stupid"

Lol. Sorry. I thought that was settled so I took it out because I too could not figure out how to have it check for both at the same time. I tried to have:

If $fileext <> ".uz2" Or $fileext <> ".au3" Then
    FileDelete($file)
EndIf

but, it didn't work as I expected it too. We kinda discussed it earlier on this thread. If it is compiled as an exe it won't be delete as it will be a file that is in use. You can't delete a file that is in use as GEOSoft pointed out. However the au3 will be deleted if it is in the same folder. Now it does not have to be in the same folder as the changedir command tells the script to change directories before proceeding. So, when you select the directory in the dialog, it changes to that directory. Is it not possible to just place the script outside the folder until you compile it? Or do you have other au3 scripts that are in this folder that you want to keep?

Edited by netman74501
Link to comment
Share on other sites

This works but its not looping :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>
$Form1 = GUICreate("",200,100)

GUISetState(@SW_SHOW)
$Start = GUICtrlCreateButton ('Start',0,0,200,20)
$pathnameinput = GUICtrlCreateInput("",0,20,200,80)
While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
       
    Case $Start
        $Dir = FileSelectFolder ("Specify directory",'')
        $pathnamevalue = GUICtrlRead ($pathnameinput)
        GUICtrlSetData ($pathnameinput, $Dir)
        FileChangeDir($Dir)
        $search = FileFindFirstFile("*.*")  
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
EndIf

While 1
If $Start = "3" Then
    ;MsgBox(0,'','button ID is 3')
    $file = FileFindNextFile($search)
    If @error Then
    ;MsgBox (0,'ERROR', 'nothing to delete')
    ExitLoop
EndIf
   $fileext = StringRight($file, 4)
    If  $fileext == ".au3" Then
        ContinueLoop
    ElseIf $fileext == ".uz2" Then
        ContinueLoop
    EndIf
    FileDelete($file)
;WEnd
;MsgBox (0,'','deleted')
EndIf
WEnd
Case $GUI_EVENT_CLOSE
    Exit
EndSwitch
WEnd

While it still running i created new text file and it just stays there not being deleted :)

How do i add loop to this so it will continuously search and delete files ?

Link to comment
Share on other sites

This works but its not looping :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>
$Form1 = GUICreate("",200,100)

GUISetState(@SW_SHOW)
$Start = GUICtrlCreateButton ('Start',0,0,200,20)
$pathnameinput = GUICtrlCreateInput("",0,20,200,80)
While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
       
    Case $Start
        $Dir = FileSelectFolder ("Specify directory",'')
        $pathnamevalue = GUICtrlRead ($pathnameinput)
        GUICtrlSetData ($pathnameinput, $Dir)
        FileChangeDir($Dir)
        $search = FileFindFirstFile("*.*")  
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
EndIf

While 1
If $Start = "3" Then
    ;MsgBox(0,'','button ID is 3')
    $file = FileFindNextFile($search)
    If @error Then
    ;MsgBox (0,'ERROR', 'nothing to delete')
    ExitLoop
EndIf
   $fileext = StringRight($file, 4)
    If  $fileext == ".au3" Then
        ContinueLoop
    ElseIf $fileext == ".uz2" Then
        ContinueLoop
    EndIf
    FileDelete($file)
;WEnd
;MsgBox (0,'','deleted')
EndIf
WEnd
Case $GUI_EVENT_CLOSE
    Exit
EndSwitch
WEnd

While it still running i created new text file and it just stays there not being deleted :)

How do i add loop to this so it will continuously search and delete files ?

You keep quoting your old code. Are you meaning too? Because I took your old code and gave you exactly what I believe you are needing. I'm sorry I do not know how to tell you to add a loop to the old code. It was hard enough to figure out on my own. If you use my code, it works. Take it, study it, learn from it. There is much more than just a loop needing added as you can see from the modified code. I'm sorry, I just don't know how to tell you how to do it except with the modified code. Edited by netman74501
Link to comment
Share on other sites

no code had some minor changes. ua3 was added so it wont be deleted its just i cant loop it adter button is pressed.

Its ok you allready helped me allot

thanks.

I'm sorry I can't help you more. I wish that I could. I just don't know how to do it with the old code. That was what the new code was for. As I said before, the new code will still delete an au3 file but it won't delete itself once compiled. For testing purposes you can just put it outside the folder you want to run it on. BTW, my code didn't delete the file right away. It took a few seconds as it had to go through every file in the folder. So if you have 100's or even 1000's of files in the folder it could take a while to go through the loop. I do not know how to speed it up either.

Edited by netman74501
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...