Sign in to follow this  
Followers 0
Merchants

help why does this not work? FileFindFirstFile()

9 posts in this topic

#1 ·  Posted (edited)

if i put the script file in the same directory as the file that i wana edit it works

but if i select folder it does not work

Why?

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#NoTrayIcon
Global $GUI[10], $Last_Folder = -1

$GUI[0] = GUICreate("Replace File name", 300, 150, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
GUICtrlCreateLabel("Folder", 5, 8)
GUICtrlCreateLabel("Find", 5, 38)
GUICtrlCreateLabel("Replace", 5, 68)
GUICtrlCreateLabel("Type file", 5, 98)
GUICtrlCreateLabel("01. (Ex file: 01. test)", 180, 38)
GUICtrlSetColor(-1, 0x009933)
GUICtrlSetFont(-1, -1, -1, 2)
GUICtrlCreateLabel("1 (Ex file after: 1 test)", 180, 68)
GUICtrlSetColor(-1, 0x009933)
GUICtrlSetFont(-1, -1, -1, 2)
GUICtrlCreateLabel("mp3 (Ex file: *.mp3)", 180, 90)
GUICtrlSetColor(-1, 0x009933)
GUICtrlSetFont(-1, -1, -1, 2)
GUICtrlCreateLabel("Default = mp3", 180, 105)
GUICtrlSetColor(-1, 0x009933)
GUICtrlSetFont(-1, -1, -1, 2)
$GUI[1] = GuiCtrlCreateInput("", 50, 5, 125, 20)
$GUI[2] = GuiCtrlCreateInput("", 50, 35, 125, 20)
$GUI[3] = GuiCtrlCreateInput("", 50, 65, 125, 20)
$GUI[4] = GuiCtrlCreateInput("", 50, 95, 125, 20)
$GUI[5] = GUICtrlCreateButton("Replace", 50, 122, 90, 22, 0x0001)
$GUI[6] = GUICtrlCreateButton("Close", 150, 122, 90, 22)
$GUI[7] = GUICtrlCreateButton("Select folder", 180, 4, 100, 22)
GUISetState()

While 1
    $GUI[9] = GUIGetMsg($GUI[0])
    Select
        Case $GUI[9] = $GUI_EVENT_CLOSE
            Exit
        Case $GUI[9] = $GUI[6]
            Exit
        Case $GUI[9] = $GUI[7]
            $sTmpFile = FileSelectFolder("Select File:", -1, 1, $Last_Folder)
            If Not $sTmpFile = "" Then
                $Last_Folder = $sTmpFile
                GUICtrlSetData($GUI[1], $sTmpFile)
            EndIf
        Case $GUI[9] = $GUI[5]
            If $GUI[2] = "" Then
                MsgBox(64,"Error","I don't know what to find!")
            Else
                If GUICtrlRead($GUI[4]) = "" Then
                    If GUICtrlRead($GUI[1]) = "" Then
                        $search = FileFindFirstFile("*.mp3")
                    Else
                        $search = FileFindFirstFile(GUICtrlRead($GUI[1]) & "\*.mp3") ; <== here is the problem don't know whats wrong...
                    EndIf
                Else
                    If GUICtrlRead($GUI[1]) = "" Then
                        $search = FileFindFirstFile("*." & GUICtrlRead($GUI[4]))
                    Else
                        $search = FileFindFirstFile(GUICtrlRead($GUI[1]) & "\*." & GUICtrlRead($GUI[4])) ; <== here is the problem don't know whats wrong...
                    EndIf
                EndIf
                If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern")
                While 1
                    $file = FileFindNextFile($search)
                    If @error Then ExitLoop
                    $text = StringReplace($file, GUICtrlRead($GUI[2]), GUICtrlRead($GUI[3]))
                    FileMove($file, $text, 0)
                WEnd
                FileClose($search)
            EndIf
    EndSelect
WEnd
Edited by Merchants

Share this post


Link to post
Share on other sites



This

If Not $sTmpFile = "" Then

is incorrect. Sounds right in your head, but no.

You want

If $sTmpFile <> "" Then

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

that was not the problem

the problem is at Case $GUI[9] = $GUI[5]

Edited by Merchants

Share this post


Link to post
Share on other sites

And other things:

Line 47: If GUICtrlRead($GUI[2]) = ""

You also need to check @error or if your replace strings are valid. If inputs 2 and 3 are blank, then StringReplace fails and returns an empty string.

Share this post


Link to post
Share on other sites

Ah. Also fails because FileFindNextFile only returns a file name, not a full path, and does not change your working directory. You'll need to supply FileMove with the full path. All my other comments are still valid though.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hm indeed ty for help is works now

Edited by Merchants

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

uhm ok that was file NAME

but can it also edit Beschrijving: titel, ondertitel, opmerkingen?

and Medium: jaar, number, ect...

Posted Image

Edited by Merchants

Share this post


Link to post
Share on other sites

nvm i already found it

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