How to Escape a Dash

Discuss and share scripts and script files...
Post Reply
benyjr
Posts: 4
Joined: 13 May 2014 04:11

How to Escape a Dash

Post 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.
Last edited by benyjr on 15 Sep 2015 14:35, edited 1 time in total.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: How to Escape a Dash

Post 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", , , "|");
        }
    }
One of my scripts helped you out? Please donate via Paypal

Online
PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: How to Escape a Dash

Post by PeterH »

Just for understandig...

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

benyjr
Posts: 4
Joined: 13 May 2014 04:11

Re: How to Escape a Dash

Post 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.

Post Reply