QUERY: strip trailing whitespace ... woes :S

Discussion in 'C++' started by KevinGPO, Feb 20, 2006.

  1. KevinGPO

    KevinGPO Guest

    I am wondering about what's the best and easiest way to strip trailing
    whitespace from every single file in a folder, recursively.

    I want to write a program/script so that you pass in a folder name and
    it'll recursively go through all sub-folders and strips trailing
    whitespace from every single file.

    Trailing whitespace includes:

    1. whitespaces at end of text lines, strip whitespace but retain text
    2. whitespaces on empty lines, strip whitespace but leave the empty
    line
     
    KevinGPO, Feb 20, 2006
    #1
    1. Advertising

  2. In message <>,
    KevinGPO <> writes
    >I am wondering about what's the best


    Define "best". Fastest? Easiest to code?

    >and easiest


    For the programmer or for the user?

    >way to strip trailing
    >whitespace from every single file in a folder, recursively.
    >
    >I want to write a program/script so that you pass in a folder name and
    >it'll recursively go through all sub-folders and strips trailing
    >whitespace from every single file.


    Standard C++ has no concept of "folder", "sub-folder" or even "every ...
    file", so the solution is inevitably going to be platform-dependent and
    off topic here. You might do better with a scripting language - for
    example, perl has easy ways of applying operations to all matching
    files.

    >Trailing whitespace includes:
    >
    >1. whitespaces at end of text lines, strip whitespace but retain text
    >2. whitespaces on empty lines, strip whitespace but leave the empty
    >line


    2 is just the special case of 1 when the text is of zero size. No need
    to treat it specially.

    std::string has lots of functions that might help - find_last_not_of,
    for example.

    --
    Richard Herring
     
    Richard Herring, Feb 20, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Les Caudle
    Replies:
    0
    Views:
    617
    Les Caudle
    Mar 7, 2004
  2. Brad Marts
    Replies:
    3
    Views:
    419
    Brad Marts
    Nov 17, 2003
  3. Aquila
    Replies:
    35
    Views:
    457
    Mathieu Bouchard
    Mar 31, 2005
  4. Taylor Strait
    Replies:
    13
    Views:
    386
    Chris Gernon
    Dec 28, 2006
  5. yelipolok
    Replies:
    4
    Views:
    270
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page