Tach die Damen und Herren, der Unwissende meldet sich wieder einmal zu Wort....
Ich sitze immernoch an diesem Programm für meinen Kollegen, das Dateinamen Kollektiv abändern soll.
Jetzt hab ich bloss noch das Problem, dass die Variablen nicht über UDF's weitergegeben werden. Weiss jemand vielleicht, wie ich diese Variablen an die UDF weitergeben kann??
Hier der Source, die Problemstelle ist bei der Funktion _Words_Upper() markiert:
Spoiler anzeigen
#include <GuiListBox.au3>
#include <String.au3>
#NoTrayIcon
[/autoit] [autoit][/autoit] [autoit]Dim $oFSO = ObjCreate('Scripting.FileSystemObject')
Dim $search_files[4000]
Dim $file_ending[4000]
Dim $numbers[40]
Dim $ending
Dim $index
Dim $end = 0
Dim $string
For $a = 1 To 39
If $a < 21 Then
$numbers[$a] = StringFormat("%02s", $a)
Else
$numbers[$a] = ($a - 20)
EndIf
Next
Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]$GUI_main = GUICreate("Chanah - by StengelProductions", 560, 500)
$group_files = GUICtrlCreateGroup("Dateien", 20, 15, 300, 460)
$list_files = _GUICtrlListBox_Create($GUI_main, "", 40, 45, 260, 400)
$add_files = GUICtrlCreateButton("Hinzufügen", 40, 440, 110, 25)
GUICtrlSetOnEvent(-1, "_add")
$del_files = GUICtrlCreateButton("Liste Löschen", 190, 440, 110, 25)
GUICtrlSetOnEvent(-1, "_del")
$group_functions = GUICtrlCreateGroup("Aktionen", 340, 15, 200, 295)
[/autoit] [autoit][/autoit] [autoit]$bs_funktion = GUICtrlCreateButton("Bodenstriche Löschen", 360, 45, 160, 25)
GUICtrlSetOnEvent(-1, "_RenameFiles")
$dash_funktion = GUICtrlCreateButton("Bindestriche Löschen", 360, 80, 160, 25)
GUICtrlSetOnEvent(-1, "_RenameFiles")
GUICtrlCreateLabel("Zu ersetzen:", 360, 115, 150)
$input_funktion = GUICtrlCreateInput("", 360, 135, 160, 25)
GUICtrlCreateLabel("Mit:", 360, 170, 160, 25)
$input_funktion1 = GUICtrlCreateInput("", 360, 190, 160, 25)
$text_funktion = GUICtrlCreateButton("Bestimme Textstelle Löschen", 360, 230, 160, 25)
GUICtrlSetOnEvent(-1, "_RenameFiles")
$number_funktion = GUICtrlCreateButton("Zahlen Löschen", 360, 265, 160, 25)
GUICtrlSetOnEvent(-1, "_del_numbers")
$upper_case_funktion = GUICtrlCreateButton("Alle Wörter Gross Schreiben", 360, 305, 160, 25)
GUICtrlSetOnEvent(-1, "_Words_Upper")
GUISetOnEvent($GUI_EVENT_CLOSE, "_terminate")
[/autoit] [autoit][/autoit] [autoit]GUISetState()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1
Sleep(100)
WEnd
Func _add()
$files = FileOpenDialog("Dateien Auswählen", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All Files (*.*)", 7, "", $GUI_main)
If Not @error Then
$search_files = StringSplit($files, "|", 1)
If @error = 1 Then
For $a = 1 To $search_files[0]
$oFile = $oFSO.GetFile($search_files[$a])
$name = $oFile.Name
$file_name = $name
Do
$ending = StringRight($file_name, 1) & $ending
$file_name = StringTrimRight($file_name, 1)
Until StringRight($file_name, 1) = "."
$ending = StringRight($file_name, 1) & $ending
$file_name = StringTrimRight($file_name, 1)
$file_ending[$end] = $ending
$ending = ""
$search_files[$a] = $file_name
If _GUICtrlListBox_FindString($list_files, $file_name, True) = -1 Then
_GUICtrlListBox_AddString($list_files, $file_name)
$end += 1
EndIf
Next
Else
For $a = 2 To $search_files[0]
$oFile = $oFSO.GetFile($search_files[$a])
$name = $oFile.Name
$file_name = $name
Do
$ending = StringRight($file_name, 1) & $ending
$file_name = StringTrimRight($file_name, 1)
Until StringRight($file_name, 1) = "."
$ending = StringRight($file_name, 1) & $ending
$file_name = StringTrimRight($file_name, 1)
$file_ending[$end] = $ending
$ending = ""
$search_files[$a] = $file_name
If _GUICtrlListBox_FindString($list_files, $file_name, True) = -1 Then
$end += 1
_GUICtrlListBox_AddString($list_files, $file_name)
EndIf
Next
EndIf
EndIf
EndFunc ;==>_add
Func _RenameFiles()
Dim $searchFor, $replaceWith
Switch @GUI_CtrlId
Case $bs_funktion
$searchFor = '_'
$replaceWith = ' '
Case $dash_funktion
$searchFor = '-'
$replaceWith = ' '
Case $text_funktion
$searchFor = GUICtrlRead($input_funktion)
$replaceWith = GUICtrlRead($input_funktion1)
If $searchFor = "" Then MsgBox(0, "Error", "Bitte geben Sie den auszuwechselnden Text ein.")
EndSwitch
If $searchFor <> "" Then
[/autoit] [autoit][/autoit] [autoit]_GUICtrlListBox_BeginUpdate($list_files)
$count = _GUICtrlListBox_GetCount($list_files)
For $a = $count - 1 To 0 Step -1
$text = _GUICtrlListBox_GetText($list_files, $a)
If @GUI_CtrlId = $upper_case_funktion Then
$file = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index])
$text = StringSplit($file.Name, " ")
For $uc = $text[0] To 1 Step -1
$new_name = StringReplace($text[$uc], StringLeft($text[$uc], 1), StringUpper(StringLeft($text[$uc], 1))) & " " & $new_name
Next
Else
$new_name = StringReplace($text, $searchFor, $replaceWith)
EndIf
_GUICtrlListBox_ReplaceString($list_files, $a, $new_name)
$index = _GUICtrlListBox_FindString($list_files, $new_name, True)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1] & $file_ending[$index])
$search_files[$a + 1] = $new_name
Else
$oFile = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index])
$search_files[$a + 2] = $new_name
EndIf
$string = $oFile.Path
$file_dir = $string
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_name & $file_ending[$index] , 1)
$new_name = ""
Next
_GUICtrlListBox_EndUpdate($list_files)
EndIf
EndFunc ;==>_RenameFiles
Func _del_numbers()
_GUICtrlListBox_BeginUpdate($list_files)
$count = _GUICtrlListBox_GetCount($list_files)
For $a = $count - 1 To 0 Step -1
$text = _GUICtrlListBox_GetText($list_files, $a)
$new_name = $text
For $i = 39 To 1 Step -1
If StringInStr($text, $numbers[$i]) Then
If StringInStr($text, $numbers[$i] & " - ") Then ;==> 01 - asdf.mp
$new_name = StringReplace($text, $numbers[$i] & " - ", "")
ElseIf StringInStr($text, $numbers[$i] & "-") Then ;==> 01-asdf.mp3
$new_name = StringReplace($text, $numbers[$i] & "-", "")
ElseIf StringInStr($text, " - " & $numbers[$i] & " - ") Then ;==> asdf - 01 - asdf.mp3
$new_name = StringReplace($text, " - " & $numbers[$i] & " -", "")
ElseIf StringInStr($text, "-" & $numbers[$i] & "-") Then ;==> asdf-01-asdf.mp3
$new_name = StringReplace($text, "-" & $numbers[$i] & "-", " - ")
ElseIf StringInStr($text, " - " & $numbers[$i]) Then ;==> asdf - 01.mp3
$new_name = StringReplace($text, " - " & $numbers[$i], "")
ElseIf StringInStr($text, "-" & $numbers[$i]) Then ;==> asdf-01.mp3
$new_name = StringReplace($text, "-" & $numbers[$i], "")
ElseIf StringInStr($text, " " & $numbers[$i] & " ") Then ;==> asdf 01 asdf.mp3
$new_name = StringReplace($text, " " & $numbers[$i] & " ", " - ")
ElseIf StringInStr($text, $numbers[$i] & ". ") Then ;==> 01. asdf.mp3
$new_name = StringReplace($text, $numbers[$i] & ". ", "")
ElseIf StringInStr($text, $numbers[$i] & ".") Then ;==> 01.asdf.mp3
$new_name = StringReplace($text, $numbers[$i] & ".", "")
EndIf
EndIf
_GUICtrlListBox_ReplaceString($list_files, $a, $new_name)
$index = _GUICtrlListBox_FindString($list_files, $new_name, True)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1] & $file_ending[$index])
$search_files[$a + 1] = $new_name
Else
$oFile = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index])
$search_files[$a + 2] = $new_name
EndIf
$string = $oFile.Path
$file_dir = $string
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_name & $file_ending[$index] , 1)
Next
Next
_GUICtrlListBox_EndUpdate($list_files)
EndFunc
Func _Words_Upper()
$count = _GUICtrlListBox_GetCount($list_files)
For $a = 1 To $count
$new_name = _StringProper(_GUICtrlListBox_GetText($list_files, $a))
_GUICtrlListBox_ReplaceString($list_files, $a, $new_name)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1] & $file_ending[$index]) <--------------- E:\Scripts\Edit\Dateinamen Ändern\Chanah.au3 (239) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$oFile = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index])
$oFile = $oFSO.GetFile(^ ERROR
$search_files[$a + 1] = $new_name
Else
$oFile = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index]) <--------------- E:\Scripts\Edit\Dateinamen Ändern\Chanah.au3 (239) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$oFile = $oFSO.GetFile($search_files[$a + 2] & $file_ending[$index])
$oFile = $oFSO.GetFile(^ ERROR
$search_files[$a + 2] = $new_name
EndIf
$string = $oFile.Path
$file_dir = $string
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_name & $file_ending[$index] , 1)
Next
EndFunc
Func _del()
_GUICtrlListBox_ResetContent($list_files)
$end = 0
EndFunc ;==>_del
Func _terminate()
Exit
EndFunc ;==>_terminate