Diana (Cda) Posted November 19, 2010 Posted November 19, 2010 I'd like to modify an old script of mine to give a more meaningful name to the resulting file. When invoked, the script always creates a file called "0- Playlist.m3u". Is there a way to get that filename to be more meaningful, so that it comes out as "0- Containing Folder name.m3u" where the "containing folder name" part gets changed to the actual name of the folder the M3U is in? i.e., if the "0- Playlist.m3u" file is located in folder "My Favourite Music", say ... how can we get output file to be automatically named "0- My Favourite Music.m3u"? I only have the first part of the script: FileMove($FileCreated, @ScriptDir & "\ Thanks.
whim Posted November 19, 2010 Posted November 19, 2010 (edited) Hi Diana, Try something like this: $FileCreated = "C:\a\b\container\0- Playlist.m3u" Local $dummy = StringSplit($FileCreated, "\") ; $dummy[0] has the number of elements ; $dummy[$dummy[0]] contains last element = filename without path ; $dummy[$dummy[0]-1] has the 1-before-last element, i.e. 'container' Local $newname = StringReplace($FileCreated, $dummy[$dummy[0]], "0- " & $dummy[$dummy[0] - 1] & ".m3u") FileMove($FileCreated, $newname) hope that helps, whim Edit: This assumes you have the full path to your playlist in $CreatedFile, and that you want your renamed playlist to replace your original one. Edited November 19, 2010 by whim
UEZ Posted November 19, 2010 Posted November 19, 2010 What about this? $path = @ScriptDir $aFilename = StringRegExp($path, ".*\\(.*)$", 3) $newFilename = "0- " & $aFilename[0] & ".m3u" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $newFilename = ' & $newFilename & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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