mr-es335 Posted December 11 Posted December 11 Good day, In the following posting, "Rename all files in a folder in numerical order", AndrewG provided two excellent working examples of a resolve to saurabh2k26's query. From that example, what is required - as noted in the title of this posing, is the ability to rename all data files in a folder based on the contents of a text file. The process is as follows: 1) Manually copy audio data to selected folder [Done! Expected!] 2) Read the contents of the target folder [Done! _CreateTextListing.au3] • Filename: FileListing.txt 3) Launch the text file [Done! _LaunchTextListing.au3] 4) Manually update the FileListing.txt [Done! Expected!] 5) Rename each file based on the contents of the FileListing.txt text file [In progress, based on AndrewG's script] • Script name: _RenameAudioData.au3 Note: The employment of the term "Expected!" simply infers that this process is expected and therefore, that I do not intend to rely on a script to perform this operation. I have attached the above scripts for perusal. The provided image displays "Before-and-After" results of my currently "manual" Steps 4-5 processes. What I AM looking for... Assistance in "how" to go about resolving the above. Think..."Teasers!" What I AM NOT looking for... A completed script. I really need to learn "how" to go about resolving such issues on my own. As always...any assistance in this matter would be greatly appreciated! _CreateTextListing.au3 _LaunchTextListing.au3 _RenameAudioData.au3 mr-es335 Sentinel Music Studios
mr-es335 Posted December 11 Author Posted December 11 Good day, This is as far as I am able to get... expandcollapse popup;https://www.autoitscript.com/forum/topic/111408-read-text-file-line-by-line/?do=findComment&comment=781873 ; ----------------------------------------------- #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- _Example() ; ----------------------------------------------- Func _Example() $file_to_read = "I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt" $file_to_write = "I:\Live_Rig\Scripts\Development\_RenameAudioData\Audio\" ; ----------------------------------------------- Local $aArray1 = FileReadToArray($file_to_read) Local $iLineCount = @extended ; ----------------- ConsoleWrite(@CRLF & "Contents of txt file" & @CRLF) For testing only! For $i = 0 To $iLineCount - 1 ConsoleWrite($aArray1[$i] & @CRLF) Next ; ----------------- ; Read the audio files Local $aArray2 = _FileListToArray($file_to_write, "*.*", $FLTA_FILES) ; ----------------- For testing only! ConsoleWrite(@CRLF & "Contents of audio folder" & @CRLF) For $i = 1 To $aArray2[0] ConsoleWrite($aArray2[$i] & @CRLF) Next ConsoleWrite(@CRLF) ; ----------------- ; Rename each file ; NOT WORKING!!! For $i = 0 To $iLineCount - 1 FileMove($aArray1, $aArray2[$i]) Next EndFunc ;==>_Example ; ----------------------------------------------- Any ideas? Anyone? mr-es335 Sentinel Music Studios
ioa747 Posted December 11 Posted December 11 _Example() ; ----------------------------------------------- Func _Example() $file_to_read = "I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt" $file_to_write = "I:\Live_Rig\Scripts\Development\_RenameAudioData\Audio\" ; ----------------------------------------------- Local $aArray1 = FileReadToArray($file_to_read) here where you find the file ? I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt I know that I know nothing
mr-es335 Posted December 11 Author Posted December 11 ioa747, May I ask what yo means by , "...here where you find the file?" mr-es335 Sentinel Music Studios
ioa747 Posted December 11 Posted December 11 that the specific script does not create the file : I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt this means that the file already exists I know that I know nothing
mr-es335 Posted December 11 Author Posted December 11 ioa747, You stated, "...that the specific script does not create the file..." ...Understood! I do know that the file was created previously, which was then manually updated to use as the "master re-namer" file. And, "...this means that the file already exists ..." ...Understood! This I also know. I am really STUCK on this section: ; Rename each file For $i = 1 To $aArray2[0] Local $sWavFileName = $aArray2[$i] Local $sWavBaseName = StringTrimRight($sWavFileName, 4) ConsoleWrite($sWavBaseName & @CRLF) ; ----------------- FileMove($aArray1, $sWavFileName[$i]) Next I have been attempting to employ the following, but this is getting me nowhere as well!?!? ; ----------------------------------------------- #include <File.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- _RenameEdls() ; ----------------------------------------------- Func _RenameEdls() ; For testing only! Local $sSrcFolder = "F:\Audio\Type_1\TomHoward\wav" Local $sDstFolder = "F:\Audio\Type_1\TomHoward\edl" Local $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\Type_1.edl" Local $sWavFileData = _FileListToArray($sSrcFolder, "*.wav", $FLTA_FILES) ; For testing only! _ArrayDisplay($sWavFileData, "$sWavFileData") ; ----------------------------------------------- For $i = 1 To $sWavFileData[0] Local $sWavFileName = $sWavFileData[$i] Local $sWavBaseName = StringTrimRight($sWavFileName, 4) ; ----------------- Local $sNewEdlFile = $sDstFolder & "\" & $sWavBaseName & ".edl" ; ----------------- FileCopy($sMasterEdlFile, $sNewEdlFile, $FC_NOOVERWRITE) ConsoleWrite($sNewEdlFile & @CRLF) Next ; ----------------- MsgBox($MB_ICONINFORMATION, "Success", "All .edl files have been created successfully.") EndFunc ;==>_RenameEdls ; ----------------------------------------------- mr-es335 Sentinel Music Studios
ioa747 Posted December 11 Posted December 11 (edited) 25 minutes ago, mr-es335 said: I am really STUCK on this section: ; Rename each file For $i = 1 To $aArray2[0] Local $sWavFileName = $aArray2[$i] Local $sWavBaseName = StringTrimRight($sWavFileName, 4) ConsoleWrite($sWavBaseName & @CRLF) ; ----------------- FileMove($aArray1, $sWavFileName[$i]) Next "I am really STUCK on this section" is not that descriptive Okay, let's start from there. what give you the ConsoleWrite($sWavBaseName & @CRLF) ? Edit: or better replace with For $i = 1 To $aArray2[0] Local $sWavFileName = $aArray2[$i] Local $sWavBaseName = StringTrimRight($sWavFileName, 4) ;~ ConsoleWrite($sWavBaseName & @CRLF) ConsoleWrite("FileMove:" & $aArray1 & ", " & $sWavFileName[$i] & @CRLF) ; ----------------- ;~ FileMove($aArray1, $sWavFileName[$i]) Next what give you the ConsoleWrite ? Edited December 11 by ioa747 I know that I know nothing
ioa747 Posted December 11 Posted December 11 Without data, I can only imagine. #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- _Example() ; ----------------------------------------------- Func _Example() $file_to_read = "I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt" $file_to_write = "I:\Live_Rig\Scripts\Development\_RenameAudioData\Audio\" ; ----------------------------------------------- Local $aArray1 = FileReadToArray($file_to_read) Local $iLineCount = @extended ConsoleWrite("$iLineCount=" & $iLineCount & @CRLF) ; Read the audio files Local $aArray2 = _FileListToArray($file_to_write, "*.*", $FLTA_FILES) For $i = 0 To $iLineCount - 1 ConsoleWrite("FileMove:" & $file_to_write & $aArray1[$i] & ", " & $file_to_write & $sWavFileName[$i + 1] & @CRLF) Next EndFunc ;==>_Example I know that I know nothing
mr-es335 Posted December 11 Author Posted December 11 (edited) ioa747, The data... Audio.zip FileListing.txt To answer your question: "ConsoleWrite($sWavBaseName & @CRLF) ? "... Bells of Charlestown ...and... "what give you the ConsoleWrite ?" "I:\Live_Rig\Scripts\Development\_RenameAudioData\_FileReadWrite2.au3" (37) : ==> Subscript used on non-accessible variable.: ConsoleWrite("FileMove:" & $aArray1 & ", " & $sWavFileName[$i] & @CRLF) ConsoleWrite("FileMove:" & $aArray1 & ", " & $sWavFileName^ ERROR Edited December 11 by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted December 11 Posted December 11 (edited) almost the same as the previous one #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- _Example() ; ----------------------------------------------- Func _Example() $file_to_read = "I:\Live_Rig\Scripts\Development\_RenameAudioData\FileListing.txt" $file_to_write = "I:\Live_Rig\Scripts\Development\_RenameAudioData\Audio\" ; ----------------------------------------------- Local $aArray1 = FileReadToArray($file_to_read) Local $iLineCount = @extended ConsoleWrite("$iLineCount=" & $iLineCount & @CRLF) ; Read the audio files Local $aArray2 = _FileListToArray($file_to_write, "*.*", $FLTA_FILES) For $i = 0 To $iLineCount - 1 ConsoleWrite("FileMove:" & $file_to_write & $aArray2[$i + 1] & ", " & $file_to_write & $aArray1[$i] & ".wav" & @CRLF) Next EndFunc ;==>_Example Edit: the question that arises will they always have the same alphabetical order? files in folder with the list? Edited December 11 by ioa747 I know that I know nothing
mr-es335 Posted December 11 Author Posted December 11 (edited) ioa747, You stated, "will they always have the same alphabetical order?" ... "Yes!" PS: Why am I NOT ABLE TO SEE THIS? "CRANIAL DEPRIVATION?" Edited December 11 by mr-es335 mr-es335 Sentinel Music Studios
mr-es335 Posted December 12 Author Posted December 12 Hello, Well, after some 12+ hours, I have this... #include <FileConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $sFolder = "I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\" Local $sfile_to_read = $sFolder & "FileListing.txt" Local $aArray1 = FileReadToArray($sfile_to_read) Local $sNewName = $sFolder & "Data\" & $aArray1[0] & ".wma" Local $sOldName = $sFolder & "Data\Bells of Charlestown.wma" FileMove($sOldName, $sNewName, $FC_OVERWRITE) EndFunc ;==>Example mr-es335 Sentinel Music Studios
mr-es335 Posted December 12 Author Posted December 12 Good day, As an important point of reference for those that tend to take "source data" as being without error - as I tend to do, and this "important point of reference" is simply this: "It is ABSOLUTELY IMPERATIVE TO UNDERSTAND that when something is only partially true, and when that something is only partially true, then that same something can also be partially false." • The "degree" of truth or falseness is dependent entirely on the scope of that something at the time. As an example, from the HelpFile, "AutoIt does not have a 'FileRename' function as you can use this function to rename a file using 'Full_Path\Old_Name' and 'Full_Path\New_Name' as the 'source" and dest' parameters." Knowing what I know now, the above statement is only partially true! The " 'tother side of the coin" is that "the entire renaming operation can take place within the very same "Full_Path\Old_Name|New_Name" location! That latter point should be assumed, but should be clearly stated as being a possibility! Regardless, I do hope this point of reference will be of some practicable employment? mr-es335 Sentinel Music Studios
mr-es335 Posted December 12 Author Posted December 12 Good day, May I ask why the last For|Next loop is NOT working? HELP?!? #include <Array.au3> #include <File.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $sTextFolder = "I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\FileListing.txt" ; Read the text file Local $sTextFileToRead = FileReadToArray($sTextFolder) ConsoleWrite("Contents of Text file..." & @CRLF) Local $sNewName = $sTextFileToRead For $i = 0 To UBound($sNewName) - 1 ConsoleWrite($sNewName[$i] & @CRLF) Next Local $sDataFolder = "I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\" ; Read the folder contents Local $aFileList = _FileListToArray($sDataFolder, "*.wma") Local $sOldName = $aFileList ConsoleWrite("Contents of Data folder..." & @CRLF) For $i = 1 To $sOldName[0] ConsoleWrite($sOldName[$i] & @CRLF) Next ; Update the folder data For $i = 1 To $sNewName[0+1] ConsoleWrite($sNewName[$i] & @CRLF) ConsoleWrite($sOldName[$i] & @CRLF) FileMove($sOldName[$i], $sNewName[$i], $FC_OVERWRITE) Next EndFunc ;==>Example mr-es335 Sentinel Music Studios
mr-es335 Posted December 12 Author Posted December 12 (edited) ioa747, So, I gather that the error is with "For $i = 1 To $sNewName[0+1]"....correct? Can anyone please, please, please give me an idea on how to get out of this "mess"? Edited December 12 by mr-es335 mr-es335 Sentinel Music Studios
Solution ioa747 Posted December 12 Solution Posted December 12 How is this different from the above? #include <Array.au3> #include <File.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $sTextFolder = "I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\FileListing.txt" ; Read the text file Local $sTextFileToRead = FileReadToArray($sTextFolder) ;~ ConsoleWrite("Contents of Text file..." & @CRLF) Local $sNewName = $sTextFileToRead ;~ For $i = 0 To UBound($sNewName) - 1 ;~ ConsoleWrite($sNewName[$i] & @CRLF) ;~ Next Local $sDataFolder = "I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\" ; Read the folder contents Local $aFileList = _FileListToArray($sDataFolder, "*.wma") Local $sOldName = $aFileList ;~ ConsoleWrite("Contents of Data folder..." & @CRLF) ;~ For $i = 1 To $sOldName[0] ;~ ConsoleWrite($sOldName[$i] & @CRLF) ;~ Next ; Update the folder data For $i = 1 To UBound($sNewName) - 1 ;~ ConsoleWrite($sNewName[$i] & @CRLF) ;~ ConsoleWrite($sOldName[$i + 1] & @CRLF) ;~ FileMove($sOldName[$i], $sNewName[$i], $FC_OVERWRITE) ConsoleWrite("FileMove:" & $sDataFolder & $sOldName[$i + 1] & ", " & $sDataFolder & $sNewName[$i] & ".wma" & @CRLF) Next EndFunc ;==>Example mr-es335 1 I know that I know nothing
mr-es335 Posted December 12 Author Posted December 12 ioa747, A couple of things: 1) I am only observing two data files being output, when there are three. Bells of Charlestown Celeste (From a Dream) First Snow of Winter 2) Second, with [$i + 1] I only observe the last two data files, and with [$i], I am only observing the first two data files. [$i + 1] FileMove:I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\Celeste (From a Dream).wma, I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\Celeste.wma FileMove:I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\First Snow of Winter.wma, I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\FirstSnowOfWinter.wma [$i] FileMove:I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\Bells of Charlestown.wma, I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\Celeste.wma FileMove:I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\Celeste (From a Dream).wma, I:\Live_Rig\Scripts\Development\_FileMove\HelpFile\Data\FirstSnowOfWinter.wma mr-es335 Sentinel Music Studios
ioa747 Posted December 12 Posted December 12 For $i = 0 To UBound($sNewName) - 1 mr-es335 1 I know that I know nothing
mr-es335 Posted December 12 Author Posted December 12 (edited) The comparisons as you noted previously: [Both look completely different to me!] Edited December 12 by mr-es335 mr-es335 Sentinel Music Studios
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now