mIRC Home    About    Download    Register    News    Help

Print Thread
Renaming a whole directories files w/o underscores #159031 12/09/06 10:07 PM
Joined: Jun 2003
Posts: 5
X
XcALiBrE Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Jun 2003
Posts: 5
I'd like to replace all the file names in my mp3 directory without $chr(95)'s. I can't get $replace to work. I am using $replace($findfile(%music.dir),$chr(95),$chr(32)) It's not working. I want EVERY file in mp3 format to be removed of all underscores($chr95). It's been about 4 years since I've really touched any scripting, so I'm a lot rusty. be patient as it'll take me a while to get back in the flow of things.

Re: Renaming a whole directories files w/o underscores #159032 12/09/06 10:59 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Replace is not rename. It just replaces it in the script itself.

You will need to run a loop of your files and do something along the lines of:

rename %originalfilename $replace(%originalfilename,_,$chr(32))

So, you might do something like:

Code:
alias ReplaceMP3s {
  if ($1) {
    var %MP3.cnt = 1
    while (%MP3.cnt > $findfile($1-,*.mp3,0)) {
      var %originalfilename = " $+ $findfile($1-,*.mp3,%MP3.cnt) $+ "
      rename %originalfilename $replace(%originalfilename,_,$chr(32))
      inc %MP3files
    }
  }
  else echo -a ERROR: Please provide a directory (in quotes if it has spaces) for your MP3s.
}


USE: /replaceMP3 path\

Make sure to put quotes around the directory path if it includes spaces.

Example:
/replaceMP3 "c:\program files\mirc\"

Also, make sure to put a \ at the end of the dir/path as shown above, or it may not work.

The only problem that I forsee is that because you're renaming files, the file number may change. You can always just run this multiple times until it's all done... it won't hurt to do so if it fails because of the file numbers in $findfile changing. Or, you can use the same type of script and store all the filenames to a file first and then rename them by reading the file rather than using $findfile each time.


Invision Support
#Invision on irc.irchighway.net
Re: Renaming a whole directories files w/o underscores #159033 13/09/06 12:37 AM
Joined: Jun 2003
Posts: 5
X
XcALiBrE Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Jun 2003
Posts: 5
Thnx... I noticed that the /inc was for a variable that wasn't used(%mp3files). I changed it to %mp3.cnt (which is what you meant I'm sure... and it worked perfectly. Thanks alot. I appreciate it.

Re: Renaming a whole directories files w/o undersc #159034 13/09/06 01:16 AM
Joined: Mar 2005
Posts: 420
X
xDaeMoN Offline
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
Here's a shorter version, without the /while loop since $findfile has it's internal loop

Code:
 alias RenameMP3 { noop $findfile($iif($1-,$1-,$sdir(c:,Select MP3 Directory)) ,*.mp3,0,.rename $qt($1-) $qt($replace($1-,_,$chr(32)))) } } 


Syntax: /renamemp3 ["c:\file\path"]

* file path is optional. A select dir dialog will pop-up if no path is entered.


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Re: Renaming a whole directories files w/o underscores #159035 13/09/06 04:33 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Sorry about that, I renamed the variable part way through and didn't fix that one. frown

XDaemon, thanks. I didn't have mIRC in front of me to figure out the internal loop in $findfile and since I rarely use it, I didn't have the syntax memorized for it. Also, good point on using $sdir.


Invision Support
#Invision on irc.irchighway.net
Re: Renaming a whole directories files w/o undersc #159036 16/09/06 06:46 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Indeed, using $findfile's internal loop is many times better than looping. $findfile is the most intensive identifier that mIRC has, you don't want to be looping with that kind of identifier unless you really really really need to. And even then...


Gone.
Re: Renaming a whole directories files w/o undersc #159037 16/09/06 06:50 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Can I also just point out that if you do script like that, you should store the result from $findfile(...,...,0) in a variable so you don't call it lots of times - the value isn't going to change.

Code:
alias ReplaceMP3s {
  if ($1) {
    var %MP3.cnt = 1, %MP3.tot = $findfile($1-,*.mp3,0)
    while (%MP3.cnt > %MP3.tot) {
      var %originalfilename = " $+ $findfile($1-,*.mp3,%MP3.cnt) $+ "
      rename %originalfilename $replace(%originalfilename,_,$chr(32))
      inc %MP3files
    }
  }
  else echo -a ERROR: Please provide a directory (in quotes if it has spaces) for your MP3s.
}


This is a general technique you should try and use, as it's much more efficient.