Jump to content

Not deleting again


Recommended Posts

This code worked before i added the gui, but now it does not delete the files it should.

;music indexer
HotKeySet("{esc}", "_exit")



#include <GUIConstants.au3>

$Form1 = GUICreate("Clean", 375, 186, 193, 123)
$Button1 = GUICtrlCreateButton("Select Folder", 144, 8, 91, 33, 0)
$Radio1 = GUICtrlCreateRadio(".mp3", 16, 88, 49, 17)
$Radio2 = GUICtrlCreateRadio(".mp4", 16, 112, 49, 17)
$Radio3 = GUICtrlCreateRadio(".jpg", 16, 136, 41, 17)
$Group1 = GUICtrlCreateGroup("Extension", 8, 72, 65, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Radio4 = GUICtrlCreateRadio("Save Extension", 96, 104, 113, 17)
$Radio5 = GUICtrlCreateRadio("Delete Extension", 96, 128, 113, 17)
$Group2 = GUICtrlCreateGroup("Options", 72, 72, 145, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Setup", 40, 8, 74, 36)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Path: ", 144, 40, 208, 33)
$Button2 = GUICtrlCreateButton("Start Clean", 256, 96, 91, 65, 0)
GUICtrlSetState ($Button2, $gui_disable)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nmsg = $GUI_EVENT_CLOSE
            Exit
        Case $nmsg = $Button1
            $path = FileSelectFolder ("Choose Folder to Clean", "")
            GUICtrlSetData ($Label2, "Path: " & $path)
            GUICtrlSetState ($Button2, $gui_enable)
        Case $nmsg = $Button2
            $mp3 = GUICtrlRead ($Radio1); 1 is selected
            $mp4 = GUICtrlRead ($Radio2)
            $jpg = GUICtrlRead ($Radio3)
            $save = GUICtrlRead ($Radio4)
            $delete = GUICtrlRead ($Radio5)
            GUIDelete ()
            ExitLoop
    EndSelect
WEnd

MsgBox (0, "", $save)


Select
    Case $mp3 = 1
        $ext = ".mp3"
    Case $mp4 = 1
        $ext = ".mp4"
    Case $jpg = 1
        $ext = ".jpg"
    Case Else
        MsgBox (0, "Error", "No extension selected.")
        Exit
EndSelect
        
Select
    Case $save = 1
        $var = 1
    Case $delete = 1
        $var = 2
    Case Else
        MsgBox (0, "Error", "Error")
EndSelect




$search = FileFindFirstFile($path & "\*.*")
SplashTextOn("", "Cleaning...", "100", "300", "-1", "-1", 3, "", "", "")
MsgBox(0, "Path to clean", $path & "\*.*")

If $var = 2 Then
While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))

    If StringRight(StringLower($file), 4) <> ".mp3" Then
        FileDelete($file)
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
    EndIf

WEnd
EndIf

If $var = 1 Then
    While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))

    If Not StringRight(StringLower($file), 4) <> ".mp3" Then
        FileDelete($file)
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
    EndIf

WEnd
Endif


SplashOff()
FileClose($search)

Func _exit()
    FileClose($search)
    Exit
EndFunc  ;==>_exit
Link to comment
Share on other sites

Trim it down so the rest of us don't have to sort through your entire script. I for one don't want to proof-read for you. Chances are, when you try and create a reproducer (smallest portion of code that reproduces the results), you'll discover the problem yourself.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

sorry this is the part i am having problems with.

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
    If Not StringRight(StringLower($file), 4) <> ".mp3" Then
        FileDelete($file)
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
    EndIf
WEnd
Link to comment
Share on other sites

That loop is inside:

If $var = 2 Then
...
EndIf

Have you checked to see if that condition is being meet?

hmmm, now I think about it maybe put both them conditions in side a single loop

While 1
If $var = 1 Then
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
    If Not StringRight(StringLower($file), 4) <> ".mp3" Then
        FileDelete($file)
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
    EndIf
Endif
If $var = 2 Then
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
    If Not StringRight(StringLower($file), 4) <> ".mp3" Then
        FileDelete($file)
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
    EndIf
EndIf
WEnd
Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Link to comment
Share on other sites

First off

If Not StringRight(StringLower($file), 4) <> ".mp3" Then

Try

If StringRight($File, 4) <> ".mp3" Then

If You are trying to do the opposite then it's

If StringRight($File, 4) = ".mp3" Then

Also in the case of large files I've found it's bettter to use this under the FileDelete($File)

While FileExists($file)
   Sleep(1)
Wend

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

Thx for the help i changed it to use stringright but it is still not deleting, and i still cannot figure out why. Here is the new code.

While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))

    If StringRight($File, 4) <> $ext Then
        FileDelete($file)
        While FileExists($file)
        Sleep(1)
        Wend
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
         Endif

WEnd
Edited by sccrstvn93
Link to comment
Share on other sites

Thx for the help i changed it to use stringright but it is still not deleting, and i still cannot figure out why. Here is the new code.

While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))

    If StringRight($File, 4) <> $ext Then
        FileDelete($file)
        While FileExists($file)
        Sleep(1)
        Wend
        SplashTextOn("", "Cleaning...   " & $file, "100", "50", "-1", "-1", 3, "", "", "")
         Endif

WEnd
OK what is $eFile and what is $ext?

If you are trying to delete everything except mp3 files then it's

If StringRight($File, 4) <> ".mp3" Then

Also your splash should be ahead of the Sleep loop otherwise it wont display until the file is gone. And if the files are deleting quickly there won't be enough time to read the splash anyway.

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

Well the splash text is more to show the user that the program has not stalled. The $efile was just there so i could verify that the string trimming was working while i was debugging it. $ext is the extension variable. So the program can work with more than one file type.

Link to comment
Share on other sites

Well the splash text is more to show the user that the program has not stalled. The $efile was just there so i could verify that the string trimming was working while i was debugging it. $ext is the extension variable. So the program can work with more than one file type.

That should work as long as you are passing $Ext to $Search

$Path = "C:\My Path\"
$Ext = "*.mp3"
$Search = FileFindFirstFile($Path & $Ext)
While 1
   $File = FileFindNextFile($Search)
   FileDelete($File)
   While FileExists($File)
      Sleep(1)
   Wend
Wend

Use a MsgBox to see that the path and filename are correct. You may find a missing backslash (common error).

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

Perhaps this may help. Your script with changes made.

;music indexer
HotKeySet("{esc}", "_exit")

Global $search

#include <GUIConstants.au3>

$Form1 = GUICreate("Clean", 375, 186, 193, 123)
$Button1 = GUICtrlCreateButton("Select Folder", 144, 8, 91, 33, 0)
$Radio1 = GUICtrlCreateRadio(".mp3", 16, 88, 49, 17)
$Radio2 = GUICtrlCreateRadio(".mp4", 16, 112, 49, 17)
$Radio3 = GUICtrlCreateRadio(".jpg", 16, 136, 41, 17)
$Group1 = GUICtrlCreateGroup("Extension", 8, 72, 65, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Radio4 = GUICtrlCreateRadio("Save Extension", 96, 104, 113, 17)
$Radio5 = GUICtrlCreateRadio("Delete Extension", 96, 128, 113, 17)
$Group2 = GUICtrlCreateGroup("Options", 72, 72, 145, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Setup", 40, 8, 74, 36)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Path: ", 144, 40, 208, 33)
$Button2 = GUICtrlCreateButton("Start Clean", 256, 96, 91, 65, 0)
GUICtrlSetState($Button2, $gui_disable)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Button1
            $path = FileSelectFolder("Choose Folder to Clean", "")
            GUICtrlSetData($Label2, "Path: " & $path)
            GUICtrlSetState($Button2, $gui_enable)
        Case $nMsg = $Button2
            $mp3 = GUICtrlRead($Radio1); 1 is selected
            $mp4 = GUICtrlRead($Radio2)
            $jpg = GUICtrlRead($Radio3)
            $save = GUICtrlRead($Radio4)
            $delete = GUICtrlRead($Radio5)
            GUIDelete()
            ExitLoop
    EndSelect
WEnd

Select
    Case $mp3 = 1
        $ext = ".mp3"
    Case $mp4 = 1
        $ext = ".mp4"
    Case $jpg = 1
        $ext = ".jpg"
    Case Else
        MsgBox(0, "Error", "No extension selected.")
        Exit
EndSelect

Select
    Case $save = 1
        $var = 1
    Case $delete = 1
        $var = 2
    Case Else
        MsgBox(0, "Error", "Error")
EndSelect

$search = FileFindFirstFile($path & "\*.*")
If $search <> -1 Then
    $handle_Splash = SplashTextOn("", "Cleaning ...", "600", "50", "-1", "-1", 32+3, "", "", "")
    ; Delete Extension
    If $var = 2 Then
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
            If StringRight($file, 4) <> $ext Then
                FileDelete($path & '\' & $file)
                ControlSetText($handle_Splash, "", "Static1", "Cleaning...   " & $file)
            EndIf
        WEnd
    EndIf
    ; Save Extension
    If $var = 1 Then
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $efile = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
            If Not StringRight($file, 4) <> $ext Then
                FileDelete($path & '\' & $file)
                ControlSetText($handle_Splash, "", "Static1", "Cleaning...   " & $file)
            EndIf
        WEnd
    EndIf
    FileClose($search)
    SplashOff()
Else
    MsgBox(0x30, @ScriptName, 'Search Failed Completely.')
EndIf

Func _exit()
    If $search And $search <> -1 Then
        FileClose($search)
    EndIf
    Exit
EndFunc  ;==>_exit

:whistle:

Link to comment
Share on other sites

Thx for the help

@MHz

but now the script deletes everything regardless of extension.

[color="#0000ff"]If[/color] [color="#0000ff"]Not[/color] [i][color="#000080"]StringRight[/color][/i]([color="#5a5a5a"]$file[/color], [color="#004040"]4[/color]) <> [color="#5a5a5a"]$ext[/color] [color="#0000ff"]Then[/color]
still does not look right

[color="#0000ff"]If[/color] [color="#0000ff"]Not[/color] [i][color="#000080"]StringRight[/color][/i]([color="#5a5a5a"]$file[/color], [color="#004040"]4[/color]) = [color="#5a5a5a"]$ext[/color] [color="#0000ff"]Then[/color]

or

[color="#0000ff"]If[/color] [i][color="#000080"]StringRight[/color][/i]([color="#5a5a5a"]$file[/color], [color="#004040"]4[/color]) <> [color="#5a5a5a"]$ext[/color] [color="#0000ff"]Then[/color]

depending on whether you want to delete the files that match $Ext or ignore files that match $Ext.

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

Thx for the help

@MHz

but now the script deletes everything regardless of extension.

I am not sure of the logic that you want but just patched up the code to working order.

Is it meant to delete the checked extensions or meant to delete all but the checked extensions?

Link to comment
Share on other sites

Is it meant to delete the checked extensions or meant to delete all but the checked extensions?

That's what I've been trying to determine since last night. That's also why I posted the code chance for either way.

If NOT something <> (NOT EQUAL TO) is a double negative and they don't work in code any better than they work in grammar.

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

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