Page 1 of 1

How to Escape a Dash

Posted: 15 Sep 2015 06:56
by benyjr
How do I escape a dash so that it appears in the file name as a dash and it doesn't behave as an operator?

I have the following script:

Code: Select all

foreach($folder, folderreport(dirsrel, r, , , , "|"), "|", , ) {
     if (foldersize("<curpath>\$folder", <d>, 0)>0) {
          $subfolder = folderreport(dirsrel, r, "<curpath>\$folder", , , "|");
          moveto "<curpath>\$folder", "<curpath>\$folder\$subfolder\*.*";
          delete 0, 0, "<curpath>\$folder\$subfolder\";
          $dash = -;
          rename b, $folder $dash <#01>, , folderreport(files, r, "<curpath>\$folder", , , "|");
     }
}
It reaches into a sub-subfolder, and moves the files to the folder above, deletes the sub-subfolder, and then renames the moved files.

Is there a more elegant way to get the dash to appear in the renaming than how I got it to work?

I tried using single quotes in various areas, but the quotes were appearing in the file name.

Thank you.

Re: How to Escape a Dash

Posted: 15 Sep 2015 08:00
by highend
You mean something like this (untested)?

Code: Select all

    foreach($folder, folderreport(dirsrel, r, , , , "|"), "|", , ) {
        if (foldersize("<curpath>\$folder", <d>, 0) >0 ) {
            $subfolder = folderreport(dirsrel, r, "<curpath>\$folder", , , "|");
            moveto "<curpath>\$folder", "<curpath>\$folder\$subfolder\*.*";
            delete 0, 0, "<curpath>\$folder\$subfolder\";
            rename b, "$folder - <#01>", , folderreport(files, r, "<curpath>\$folder", , , "|");
        }
    }

Re: How to Escape a Dash

Posted: 15 Sep 2015 10:49
by PeterH
Just for understandig...

At least $dash = -; should have been $dash = '-'; - shouldn't it?

Re: How to Escape a Dash

Posted: 15 Sep 2015 14:34
by benyjr
@PeterH,

It seems to work either way.

@highend

Code: Select all

rename b, "$folder - <#01>", , folderreport(files, r, "<curpath>\$folder", , , "|");
This does work! Thank you! I was only using single quotes and didn't think to use double quotes instead.