#include-once #include #include #include #include #include #include #include #include #include Global $aFileList Global $sFileSelectFolder = "" Global $sFileDestinationFolder = "C:\Users\Pete\Desktop\BookLists" Global $i = 0 Global $n = 1 Global $isMP3 = 0 $totalfiles = 0 Global $FIRSTAuthor = "" Global $FIRSTBook = "" Global $SECONDAuthor = "" Global $SECONDBook = "" Global $NoOfCSVs = 0 Local $idRdo, $idRdo2, $idRdo3, $idChk ;*************** Create GUI GUICreate("MP3 Catalog & Search", 1200, 500, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color ;Create a text box where we show some results $g_idMemo = GUICtrlCreateEdit("List of Albums", 120, 200, 900, 200, $WS_VSCROLL) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") ; create radio buttons that recreate out CSV files IF NECESSARY $idRdo = GUICtrlCreateRadio("Recreate Music File", 10, 10, 200, 50) $idRdo2 = GUICtrlCreateRadio("Recreate PS AudioBooks File", 10, 60, 200, 50) $idRdo3 = GUICtrlCreateRadio("Recreate KJS AudioBooks File", 10, 100, 200, 50) ;Create the EXIT button. Local $idButton_Close = GUICtrlCreateButton("EXIT", 210, 170, 85, 25) ;create a place to enter our search AUTHOR / ARTIST string Local $SEARCH_AUTHOR = GUICtrlCreateInput("AUTHOR / ARTIST", 300, 10, 300, 20) ;create a place to enter our search ALBUM / TITLE string Local $SEARCH_ALBUM = GUICtrlCreateInput("ALBUM / TITLE", 300, 60, 300, 20) ;create a place to enter our search TRACK string Local $SEARCH_TRACK = GUICtrlCreateInput("TRACK", 300, 120, 300, 20) GUISetState(@SW_SHOW) ;************************************* start doing STUFF! ;while the exit button Is not pressed ;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz ;this while loop recreates the csv files, if the user hits a radio button While $sFileSelectFolder = "" $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRdo And BitAND(GUICtrlRead($idRdo), $GUI_CHECKED) = $GUI_CHECKED $sFileSelectFolder = "H:\MP3\Music" ;*************************** Open the CSV file $DestFile = $sFileDestinationFolder & "\MP3 MUSIC List.csv" $hfileopen = FileOpen($DestFile, $FO_OVERWRITE + $FO_CREATEPATH) MsgBox($MB_SYSTEMMODAL, 'Info:', $DestFile) ;*************************** Create an array containing all file names _Listfile() ;*************************** Populate the CSV File _createCSV() Case $idMsg = $idRdo2 And BitAND(GUICtrlRead($idRdo2), $GUI_CHECKED) = $GUI_CHECKED $sFileSelectFolder = "H:\MP3\Audiobooks" $DestFile = $sFileDestinationFolder & "\MP3 PS BOOKS List.csv" $hfileopen = FileOpen($DestFile, $FO_OVERWRITE + $FO_CREATEPATH) ;MsgBox($MB_SYSTEMMODAL, 'Info:', $hfileopen) ;*************************** Create an array containing all file names _Listfile() ;*************************** Populate the CSV File _createCSV() Case $idMsg = $idRdo3 And BitAND(GUICtrlRead($idRdo3), $GUI_CHECKED) = $GUI_CHECKED $sFileSelectFolder = "H:\MP3\KJS Audiobooks" $DestFile = $sFileDestinationFolder & "\MP3 KJS BOOKS List.csv" $hfileopen = FileOpen($DestFile, $FO_OVERWRITE + $FO_CREATEPATH) ;MsgBox($MB_SYSTEMMODAL, 'Info:', $hfileopen) ;*************************** Create an array containing all file names _Listfile() ;*************************** Populate the CSV File _createCSV() EndSelect WEnd ;************ OK! Thats the "make the CSV files bit over with! ; NOW! we needs to search a CSV file for a string & display the results ;***************************************************************************** ;functions live below here ;***************************************************************************** Func _Listfile() ; List all the files and folders in the desktop directory using the default parameters and return the full path. Global $aFileList = _FileListToArrayRec($sFileSelectFolder, "*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ; Display the results returned by _FileListToArray. ;_ArrayDisplay($aFileList, "$aFileList") EndFunc ;==>_Listfile Func _createCSV() ;MsgBox($MB_SYSTEMMODAL, "", $aFilelist[0]) ;_ArrayDisplay($aFileList, "$aFileList") ;*************************** find the first MP3 file While $isMP3 = 0 $n = $n + 1 $isMP3 = StringInStr($aFileList[$n], ".mp3") WEnd ;***************** create the full file path $Filename = $sFileSelectFolder & "\" & ($aFileList[$n]) ;***************** Read the Tags $sFileTagInfo = _ID3ReadTag($Filename) ;**************** Assign the ALBUM and AUTHOR (Artist) tags to variables - this is our INITIAL starting point $FIRSTBook = _ID3GetTagField("TALB") $FIRSTAuthor = _ID3GetTagField("TPE1") ;MsgBox($MB_SYSTEMMODAL, "", $FIRSTAuthor,2) ; ****************** For every file in the structure:- For $i = 1 To $aFileList[0] ;******************** Is the file an MP3 file? $isMP3 = StringInStr($aFileList[$i], ".mp3") If $isMP3 <> 0 Then ; So StringInStr returns an integer IF the string is found ; ***** Create the full file path for THIS file. $Filename = $sFileSelectFolder & "\" & ($aFileList[$i]) ;***** Read the Tags to different variables. $sFileTagInfo = _ID3ReadTag($Filename) $SECONDBook = _ID3GetTagField("TALB") $SECONDAuthor = _ID3GetTagField("TPE1") ;MsgBox($MB_SYSTEMMODAL, "", $SECONDAuthor,2) ;MsgBox($MB_SYSTEMMODAL, "", $SECONDBook,2) EndIf If $SECONDBook <> $FIRSTBook Then ;*************** compare the tags found initially with the tags found now ; ************** If the tags are different, write the first set of tags to the CSV file FileWriteLine($hfileopen, $FIRSTAuthor & "**" & $FIRSTBook & @CRLF) ;********** copy the tags found now over the first set of tags. $FIRSTAuthor = $SECONDAuthor $FIRSTBook = $SECONDBook ; ************* display something to reassure the user that something is happening GUICtrlSetData($g_idMemo, $FIRSTBook & @CRLF & @CRLF, 1) ;MsgBox($MB_SYSTEMMODAL, "", $aFileList[$i],1) EndIf $isMP3 = 0 Next FileWriteLine($hfileopen, $FIRSTAuthor & "**" & $FIRSTBook) FileClose($hfileopen) EndFunc ;==>_createCSV