Jump to content
Sign in to follow this  
Diana (Cda)

File rename: take containing folder name in title?

Recommended Posts

Diana (Cda)

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. :graduated:

Share this post

Link to post
Share on other sites

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,


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 by whim

Share this post

Link to post
Share on other sites

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



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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.