Also guten Tag erst mal...
Da mein Kollege gerne mal ein bisschen was an Musik runterlädt und sich dabei zu tode nervt weil die Dateinamen immer Bodenstriche oder anderes unbrauchbares Zeug drin haben, hat er mich gefragt, ob ich ihm ein Programm zur korrektur dieser Dateinamen schreiben könnte...
Dann erst mal der Code:
Spoiler anzeigen
#Include <GuiListBox.au3>
[/autoit] [autoit][/autoit] [autoit]Dim $oFSO = ObjCreate('Scripting.FileSystemObject')
Dim $search_files[1000]
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, $LBS_EXTENDEDSEL)
$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, 255)
$bs_funktion = GUICtrlCreateButton("Bodenstriche entfernen", 360, 45, 160, 25)
GUICtrlSetOnEvent(-1, "_bodenstriche_del")
$dash_funktion = GUICtrlCreateButton("Bindestriche entfernen", 360, 80, 160, 25)
GUICtrlSetOnEvent(-1 , "_bindestriche_del")
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 entfernen", 360, 235, 160, 25)
GUICtrlSetOnEvent(-1, "_bestimmte_textstelle_del")
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])
_GUICtrlListBox_AddString($list_files, $oFile.Name)
Next
Else
For $a = 2 To $search_files[0]
$oFile = $oFSO.GetFile($search_files[$a])
_GUICtrlListBox_AddString($list_files, $oFile.Name)
Next
EndIf
EndIf
EndFunc
Func _del()
_GUICtrlListBox_ResetContent($list_files)
EndFunc
Func _bodenstriche_del()
_GUICtrlListBox_BeginUpdate($list_files)
$count = _GUICtrlListBox_GetCount($list_files)
For $a = $count -1 To 0 Step -1
$text = _GUICtrlListBox_GetText($list_files, $a)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1])
Else
$oFile = $oFSO.GetFile($search_files[$a + 2])
EndIf
$new_text = StringReplace($text, "_", " ")
$string = $oFile.Path
$file_dir = $string
_GUICtrlListBox_DeleteString($list_files, $a)
_GUICtrlListBox_AddString($list_files, $new_text)
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_text, 1)
Next
_GUICtrlListBox_EndUpdate($list_files)
EndFunc
Func _bindestriche_del()
_GUICtrlListBox_BeginUpdate($list_files)
$count = _GUICtrlListBox_GetCount($list_files)
For $a = $count -1 To 0 Step -1
$text = _GUICtrlListBox_GetText($list_files, $a)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1])
Else
$oFile = $oFSO.GetFile($search_files[$a + 2])
EndIf
$new_text = StringReplace($text, "-", " ")
$string = $oFile.Path
$file_dir = $string
_GUICtrlListBox_DeleteString($list_files, $a)
_GUICtrlListBox_AddString($list_files, $new_text)
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_text, 1)
Next
_GUICtrlListBox_EndUpdate($list_files)
EndFunc
Func _bestimmte_textstelle_del()
_GUICtrlListBox_BeginUpdate($list_files)
$count = _GUICtrlListBox_GetCount($list_files)
For $a = $count -1 To 0 Step -1
$text = _GUICtrlListBox_GetText($list_files, $a)
If $count = 1 Then
$oFile = $oFSO.GetFile($search_files[$a + 1])
Else
$oFile = $oFSO.GetFile($search_files[$a + 2])
EndIf
$new_text = StringReplace($text, GUICtrlRead($input_funktion), GUICtrlRead($input_funktion1))
$string = $oFile.Path
$file_dir = $string
_GUICtrlListBox_DeleteString($list_files, $a)
_GUICtrlListBox_AddString($list_files, $new_text)
Do
$file_dir = StringTrimRight($file_dir, 1)
Until StringRight($file_dir, 1) = "\"
FileMove($oFile.Path, $file_dir & $new_text, 1)
Next
_GUICtrlListBox_EndUpdate($list_files)
EndFunc
Func _terminate()
Exit
EndFunc
Bei der ersten Korrektur der Dateinamen funktioniert alles perfekt.
Aber beim zweiten mal kommt die Fehlermeldung in der Console:
E:\Scripts\Edit\Dateinamen Ändern\Chanah.au3 (70) : ==> The requested action with this object has failed.:
$oFile = $oFSO.GetFile($search_files[$a + 2])
$oFile = $oFSO.GetFile($search_files[$a + 2])^ ERROR
Weiss vielleicht jemand, warum diese Fehlermeldung erst beim 2. oder 3. mal beim Ausführen der Funktion kommt?
Ich hab schon stundenlang "herumgepröbelt" und bin dabei auf keine perfekt funktionierende Lösung gekommen...
Hoffe Ihr könnt mir helfen..
MfG, Der Unwissende