Jump to content

help why does this not work? FileFindFirstFile()


Recommended Posts

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
Link to comment
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.

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