1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wierd problem wih "for" command...

Discussion in 'Support' started by mathewsdw, Mar 6, 2011.

  1. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    I'm not sure I'm posting this in the right place, but I have a weird problem with the following command:

    Code:
    For /R G:\ /D %D in (*) Do (Echo %@Right[17,%@Repeat[ ,17]%@Comma[%@FileSize["%D"]]] %@Right[17,%@Repeat[ ,17]%@Comma[%@FileSize[/S "%D"]]] %D) | Sort /+1 >>Z:\G-Drive.txt
    The problem? While it mostly works I get a series of messages (129 of them to be exact) that are similar to the following.

    I even get a message stating:

    And, as you can see, there is no "rename" command in the above sequence.

    I'll admit that this more academic than anything else, but I would really like to know what's going on here and if there is some way for me to avoid these messages.

    TCC 12.01.44 Windows 7 [Version 6.1.7600]
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: mathewsdw
    To: ESFabian@zenge.org
    Sent: Sunday, 2011. March 6. 19:12
    Subject: [Support-t-2654] Wierd problem wih "for" command...

    | I'm not sure I'm posting this in the right place, but I have a weird
    | problem with the following command:
    |
    |
    | Code:
    | For /R G:\ /D %D in (*) Do (Echo %@Right[17,%@Repeat[
    | ,17]%@Comma[%@FileSize["%D"]]] %@Right[17,%@Repeat[
    | ,17]%@Comma[%@FileSize[/S "%D"]]] %D) | Sort /+1 >>Z:\G-Drive.txt

    | The problem? While it mostly works I get a series of messages (129 of
    | them to be exact) that are similar to the following.
    ...

    I suspect you have filenames (or directory names) on your G: drive which include your command separator ("compound") character [by default it is the ampersand &], thus the rest of the file name is considered to be a command but it is not a legal command. What could be worse than just the error message if the command is legal and its execution undesirably alters your file system (deletes or modifies files). You need to quote it to eliminate this possibility everywhere.

    BTW, the @FILESIZE command can return a size with embedded commas: %@filesize["%d",bc] - you do not need to use the @comma function. If you want the filesize to be right justified in a 17-column field, the simplest way is %@format[17,%@filesize["%d",bc]]. You could just define a function:
    function fs17=`%@format[17,%@filesize[%1,bc]]`
    and use it to simplify your command.
    --
    Steve
     
  3. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Thank you, Steve, you are, of course, correct. I am careful to NOT make file and directory names that way myself, but files I import from outside sources (the case here) sometimes use those characters and I don't notice.

    And thank you again, Steve, I didn't know some of the above and I'll (try to remember to) do it that way in the future. But it really doesn't matter that much because I didn't find it particularly difficult (either to compose or type) to do it the way I did do it.
     

Share This Page