Hallo,
hier ist ein kleines aber feines und bestimmt für einige gut zu brauchendes Script:
GtaSpider hat das Script geprogt und Ihm gilt daher mein Dank.
Es kopiert aus einem Ordner(Festplatte) Tracks zufällig, wie der Name schon sagt, an einen MP3-Player oder anderes Ziel.
Alles lässt sich über eine Gui einstellen ....
Spoiler anzeigen
; =============================================================
;
; Zufallskopierer für Musiktracks in MP3
;
; Idee: Chicago
;
; Author: GtaSpider
;
; =============================================================
#include <file.au3>
#include <array.au3>
#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1)
Global $hwndSpl, $SplNext = 1, $SplText, $FileList, $size = 0
Global $ListTxt = @ScriptDir & "\List.txt"
Global $ListTxtOp = FileOpen($ListTxt, 1)
Global $FilesToCopy[1]
$maingui = GUICreate("MP3-Zufallskopierer", 200, 200, 193, 125)
;GUISetOnEvent($GUI_EVENT_CLOSE, "_exit";) ;Da GuigetMsg() nicht mehr funktinoiert, da OnEventMode 1 ist
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$MusicInp = GUICtrlCreateInput("", 8, 24, 121, 21)
GUICtrlCreateLabel("Musik Ordner:", 8, 8, 68, 15)
$TargetInp = GUICtrlCreateInput("", 8, 64, 121, 21)
GUICtrlCreateLabel("Ziel Ordner:", 8, 48, 68, 15)
$ChooseBut1 = GUICtrlCreateButton("..", 129, 24, 27, 21, 0)
GUICtrlSetOnEvent(-1, "_search_path")
$ChooseBut2 = GUICtrlCreateButton("..", 129, 64, 27, 21, 0)
GUICtrlSetOnEvent(-1, "_search_path")
GUICtrlCreateLabel("Größe in mb:", 8, 90, 68, 15)
$GroesseInp = GUICtrlCreateInput("", 8, 105, 121, 21)
$StartBut = GUICtrlCreateButton("&Start", 8, 150, 148, 25, 0)
GUICtrlSetOnEvent(-1, "_Start")
$Progress = GUICtrlCreateProgress(8, 138, 148, 9)
GUISetState()
While 1;Damit das Script nicht beendet
Sleep(100)
WEnd
Func _search_path()
$path = FileSelectFolder("", 3 ,1,"::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
If @error Then Return
If @GUI_CtrlId = $ChooseBut1 Then; wenn als letzes ChosseBut1 gedrückt wurde (der button für den Musik Ordner)...
If $path <> "" Then GUICtrlSetData($MusicInp, $path);...setze das control $MusicInp (Musik Ordner) mit dem Pfad
Else; ansonsten (also wenn der button für den Ziel ordner gedrückt wurde) ...
If $path <> "" Then GUICtrlSetData($TargetInp, $path);...setze das control $TargetInp (Ziel Ordner) mit dem Pfad
EndIf
EndFunc ;==>_search_path
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]If FileGetSize($ListTxt) Then _ReadFromList()
[/autoit] [autoit][/autoit] [autoit]Func CLOSEClicked()
Exit
EndFunc
Func _Start()
;DIESE DATEN MUSST DU NACH DEINEN WÜNSCHEN BEARBEITEN <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $MusicDir = GUICtrlRead($MusicInp) ; Laufwerk auf dem Musik ist >> soll in Gui ausgewählt werden können
Global $SizeInByte = GUICtrlRead($GroesseInp) * 1048576 ; Berechnet die Größe der zu kopierenden Dateimengen 3750 * 1048576 = ca. 4 GB
Global $DestDir = GUICtrlRead($TargetInp) ; Laufwerk MP3-Player >> Zielort Auswahl in Gui Ordner oder MP3-Player
Global $MusicDirName = StringTrimLeft($MusicDir, StringInStr($MusicDir, "", 0, -1))
If Not IsArray($FileList) Then _ReadMusicDir()
[/autoit] [autoit][/autoit] [autoit]$SplText = "Kopiere Daten"
$hwndSpl = SplashTextOn("", $SplText & @LF & "|", 250, 65, -1, -1, 1, "Courier New")
AdlibEnable("_SetSpl", 100)
If Not FileExists($DestDir) Then DirCreate($DestDir)
[/autoit] [autoit][/autoit] [autoit]$mb = 0
$rand = 0
$InUseRead = FileRead("InUse_do_not_delete.txt";)
$InUse = $InUseRead
While 1
$SplText = "Kopiere Daten" & @CRLF & StringTrimLeft($FileList[$rand], StringInStr($FileList[$rand], "", -1, -1))
$aInUse = StringSplit($InUse, ",")
$RandInUse = True
While $RandInUse
$rand = Random(1, $FileList[0], 1)
$RandInUse = False
For $i = 1 To $aInUse[0]
ConsoleWrite($rand & "," & $aInUse[$i] & @CRLF)
If $rand = $aInUse[$i] Then
$RandInUse = True
ExitLoop
EndIf
Next
WEnd
$mb += FileGetSize($FileList[$rand])
If $mb > $SizeInByte Then ExitLoop
FileCopy($FileList[$rand], $DestDir & "\*.*")
$InUse &= $rand & ","
WEnd
FileWrite("InUse_do_not_delete.txt", StringTrimLeft($InUse, StringLen($InUseRead)))
[/autoit] [autoit][/autoit] [autoit]SplashOff()
EndFunc ;==>_Start
Func OnAutoItExit()
FileClose($ListTxtOp)
EndFunc ;==>OnAutoItExit
Func _ReadMusicDir()
$SplText = "Lese den Musikordner ein" & @LF & $MusicDirName
$hwndSpl = SplashTextOn("", $SplText & @LF & "|", 250, 40, -1, -1, 1, "Courier New")
AdlibEnable("_SetSpl", 100) ; <<<<< Hier kommt die Fehlermeldung
FileDelete("InUse_do not delete.txt")
$FileList = _FileListToArrayEx($MusicDir, "*.*", 1, '', True)
SplashOff()
AdlibDisable()
FileWriteLine($ListTxtOp, $MusicDir)
For $i = 1 To $FileList[0]
FileWriteLine($ListTxtOp, StringTrimLeft($FileList[$i], StringLen($MusicDir) + 1))
Next
EndFunc ;==>_ReadMusicDir
Func _ReadFromList()
$SplText = "Lese daten von Datei" & @LF & StringTrimLeft($ListTxt, StringInStr($ListTxt, "", 0, -1))
$hwndSpl = SplashTextOn("", $SplText & @LF & "|", 250, 65, -1, -1, 1, "Courier New")
AdlibEnable("_SetSpl", 100)
_FileReadToArray($ListTxt, $FileList)
Global $MusicDir = $FileList[1]
$FileList[0] = $FileList[0] - 1
_ArrayDelete($FileList, 1)
For $i = 1 To $FileList[0]
$FileList[$i] = $MusicDir & "" & $FileList[$i]
If Not FileExists($FileList[$i]) Then MsgBox(0, "", $FileList[$i])
Next
SplashOff()
EndFunc ;==>_ReadFromList
Func _SetSpl()
Switch $SplNext
Case 1
ControlSetText($hwndSpl, "", "Static1", $SplText & @LF & "./.")
$SplNext = 2
Case 2
ControlSetText($hwndSpl, "", "Static1", $SplText & @LF & "..-..")
$SplNext = 3
Case 3
ControlSetText($hwndSpl, "", "Static1", $SplText & @LF & "...\...")
$SplNext = 4
Case 4
ControlSetText($hwndSpl, "", "Static1", $SplText & @LF & "|")
$SplNext = 1
EndSwitch
EndFunc ;==>_SetSpl
;===============================================================================
; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax: _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $bTmpFile = False)
; Parameter(s): $sPath = Path to generate filelist for
; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
; Example *.exe; *.txt will find all .exe and .txt files
; $iFlag = determines weather to return file or folders or both.
; $sExclude = exclude a file from the list by all or part of its name
; Example: Unins* will remove all files/folders that start with Unins
; $iFlag=0(Default) Return both files and folders
; $iFlag=1 Return files Only
; $iFlag=2 Return Folders Only
; $bTmpFile = Boolean value for specifying if using a temp. file
; $bTmpFile = True All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
; The Reserved file is then read into an array, then deleted
; $bTmpFile = False No .tmp file is used
; Requirement(s): None
; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
; @Error or @extended = 1 Path not found or invalid
; @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
; @Error or @extended = 3 Invalid $iFlag
; @Error or @extended = 4 No File(s) Found
; Author(s): SmOke_N
; Note(s): The array returned is one-dimensional and is made up as follows:
; $array[0] = Number of Files\Folders returned
; $array[1] = 1st File\Folder
; $array[2] = 2nd File\Folder
; $array[3] = 3rd File\Folder
; $array[n] = nth File\Folder
;===============================================================================
Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False, $iShortName = True)
If Not FileExists($sPath) Then Return SetError(1, 1, '')
If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
$sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
For $iCC = 0 To 5
If StringInStr($sFilter, $aBadChar[$iCC]) Or _
StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
Next
If StringStripWS($sFilter, = '' Then Return SetError(2, 2, '')
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
$sTFolder = $oFSO.GetSpecialFolder (2)
Local $hOutFile = @TempDir & $oFSO.GetTempName
If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
For $iCC = 1 To $aSplit[0]
If StringStripWS($aSplit[$iCC], = '' Then ContinueLoop
If StringLeft($aSplit[$iCC], 1) = '.' And _
UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
$sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
Next
$sHoldSplit = StringTrimRight($sHoldSplit, 1)
If $iRecurse Then
RunWait(@ComSpec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
Else
RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
EndIf
$sRead &= FileRead($hOutFile)
If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
FileDelete($hOutFile)
If StringStripWS($sRead, = '' Then SetError(4, 4, '')
Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
Local $sHold
For $iCC = 1 To $aFSplit[0]
If $sExclude And StringLeft($aFSplit[$iCC], _
StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
Switch $iFlag
Case 0
If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then
If $iShortName Then
$sHold &= FileGetShortName($sPath & $aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
EndIf
Else
If $iShortName Then
$sHold &= FileGetShortName($aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $aFSplit[$iCC] & Chr(1)
EndIf
EndIf
Case 1
If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then
If $iShortName Then
$sHold &= FileGetShortName($sPath & $aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
EndIf
Else
If $iShortName Then
$sHold &= FileGetShortName($aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $aFSplit[$iCC] & Chr(1)
EndIf
EndIf
Case 2
If Not StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then
If $iShortName Then
$sHold &= FileGetShortName($sPath & $aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
EndIf
Else
If $iShortName Then
$sHold &= FileGetShortName($aFSplit[$iCC]) & Chr(1)
Else
$sHold &= $aFSplit[$iCC] & Chr(1)
EndIf
EndIf
EndSwitch
Next
$sHold = StringReplace(StringReplace(StringReplace(StringReplace($sHold, Chr(129), "ü"), Chr(132), "ä"), Chr(148), "ö"), Chr(225), "ß")
If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
Return SetError(4, 4, '')
EndFunc ;==>_FileListToArrayEx