mIRC Home    About    Download    Register    News    Help

Topic Options
#247536 - 07/08/14 02:23 PM Workaround for $isdir, /mkdir one word
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
Hey, I'm trying to create a script that moves my files from a dir to a subdir.

Basically, I have new files in H:\Anime popping up each day, and I want this script to automatically move them to H:\Anime\Filename, or create a dir if one doesn't exist.
However. When I tried doing this, I noticed that trying to create a dir called "Test 2" or trying to read if $isdir it would never use anything more than the first word.

Help would be appreciated!

Including script and reference picture with echo.
Code:
alias FolderSort { 
  var %main H:\Anime
  var %files $findfile(%main,*.mkv,0,0)
  while %files {
    var %file $findfile(%main,*.mkv,%files)
    var %regex /(\[HorribleSubs\] .+ -)/iS
    if ($regex(%file,%regex)) var %file $remove($regml(1),-,[HorribleSubs]) 
    echo -ag %file
    if (!$isdir(%main $+ \ $+ %file)) { 
      echo 3 -ag I had to create a folder for %file in %main $+ .
      mkdir %main $+ \ $+ %file
    }
    dec %files
  }
}
Originally Posted By: Echo
Tokyo Ghoul
I had to create a folder for Tokyo Ghoul in H:\Anime.
Love Stage!!
I had to create a folder for Love Stage!! in H:\Anime.

As you can see, it created the Tokyo folder when a Tokyo Ghoul folder was already created, and same with the other file. Moving them does not work either, it will not use 2 word filenames either.
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#247538 - 07/08/14 03:12 PM Re: Workaround for $isdir, /mkdir one word [Re: Nillen]
Iire Offline
Babel fish

Registered: 06/08/13
Posts: 73
When dealing with file/directory manipulation in a command, you should always surround the path in double quotes - either with the $qt() identifier, or with literal " " characters (and $+ where necessary). This ensures that the entire path is used in the command, even if it contains spaces. This is not necessary within identifiers since parameters are comma rather than space separated.

Example:
Code:
mkdir $qt(%main $+ \ $+ %file)

Top
#247539 - 07/08/14 03:43 PM Re: Workaround for $isdir, /mkdir one word [Re: Nillen]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
Btw, you're using $findfile somewhat incorrectly, $findfile itself is a loop, using it inside your while loop like this makes things much much slower, you could use something like this, which only calls $findfile once ( while your code call $findfile once to get the number of files, and then once each time the loop iterates):

Code:
alias FolderSort {
  var %main H:\Anime\
  noop $findfile(%main,*.mkv,0,0, noop $handle_anime(%main,$nopath($1-)))
}
alias handle_anime {
  var %pattern /(\[HorribleSubs\] .+ -)/iS
  if ($regex($2-,%pattern)) {
    var %f $remove($regml(1),-,[HorribleSubs])
    if (!$isdir($1- $+ %f)) mkdir $qt($1- $+ %f) 
    ; rename $qt($1- $+ $2-) $qt($1- $+ %f $+ \ $+ $2-)
  }
}

_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#247546 - 08/08/14 11:16 AM Re: Workaround for $isdir, /mkdir one word [Re: Wims]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
Thanks Wims! I never even thought of the fact that I could use an alias on the identifier when I read it in the help files. I guess it's my lack of experience smile

I noticed something about it though, and this is from my original code:

echo -ag %f
echo -ag test $+ %f
Would return
Tokyo Ghoul
test Tokyo Ghoul

So I replaced spaces with _ to see if I had a space in the beginning:
_Tokyo_Ghoul
test_Tokyo_Ghoul

Took me a while to figure out why I was getting a path with a space in the beginning, but as soon as I did it was an easy fix smile
I believe it was cause the files look like [HorribleSubs] Anime name, and I removed the [HorribleSubs], leaving a space behind.
Code:
alias FolderSort {
  var %main H:\Anime\
  noop $findfile(%main,*.mkv,0,0, noop $handle_anime(%main,$nopath($1-)))
}

alias handle_anime {
  var %pattern /(\[HorribleSubs\] .+ -)/iS
  if ($regex($2-,%pattern)) {  
    var %f $remove($regml(1),-,[HorribleSubs] )
    var %f $mid(%f,2-)
    if (!$isdir($1 $+ %f)) { 
      echo 4 -ag I had to make a new folder for %f $+ .
      mkdir $qt($1 $+ %f) 
    }
    else { 
      rename $qt($1 $+ $2-) $qt($1 $+ %f $+ \ $+ $2-)
      echo 3 -ag Moved %f without a problem.
    }
  }
}
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#247552 - 08/08/14 05:43 PM Re: Workaround for $isdir, /mkdir one word [Re: Nillen]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
Yeah, and because you were using /var, which is actually one of the unique command preserving spaces (only a single trailing space is not retained with /var)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#247553 - 08/08/14 06:38 PM Re: Workaround for $isdir, /mkdir one word [Re: Wims]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
Ah, thanks. Good to know.
I'll keep that in mind for the future. smile
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top