Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Dealing with strings

    I have some code to extract my user files by fiddling with findstr -v etc. to produce a list of directories. I thought I remembered a way to remove empty directories by piping stuff together but now recall has failed.
    I think I can get it if I can find a way to looking for "0 Files" then ignoring the previous 3 lines (the blank one I can remove in advance) and that one created by dir.
    If someone is familiar with batch commands please, as NET, C, C##, etc will not be useful in this instance, help me with this. THANKS

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 985 Times in 915 Posts
    Findstr reads files so it won't read anything in an empty directory. How are you using it that you have a problem?
    Can you post screen shots of the output you actually get and what you want?

    cheers, Paul

  3. #3
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Dealing with strings

    I am not using findstr in the manner you suggest. After I get rid of the empty directories I have a pipe of findstr to further separate the data as I need that is where I use findstr. Should be obvious on reading my post, sorry if that post is curt.
    I am seeking a command set that after I get the "0 Files" (s may be in () I don't remember) line then possibly using that line number omit/erase that line and the 3 prior lines (having removed the blank lines previously). Note I hope these lines can be a pipe of commands.

    I am looking for a command set/pipes that to remove 3 prior lines knowing that 0 Files line is the last line of an empty directory as listed by dir.

    Responding to UR request, how can I post something I don't have? That is the purpose of my query so I don't understand UR response. If I had that why would I be posting?

    Hopefully someone more fluent than I with batch commands has a suggestion on how to remove n-number of prior lines once a specific line has been identified and do it in a pipe.
    Last edited by spark55; 2015-10-04 at 05:04.

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 985 Times in 915 Posts
    Using "dir /b /a-d" will list only files, or "file not found" if there are none. Using this in a FOR allows you to run against the file names or do nothing if "file not found" is returned.

    Code:
    for /f %I in ('dir /b /a-d') do echo %I
    I don't get the bit about "list of directories". Can you give us an example of input vs output you require?

    cheers, Paul

  5. #5
    4 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    561
    Thanks
    51
    Thanked 68 Times in 66 Posts
    Hi,

    You cannot use FindStr in exactly the way you describe.

    The issue is that FindStr reads the file one line at a time and processes that line, without regards to the others. When you say you want to "ignore the previous 3 lines", well FindStr cannot do that. At that point those lines have been processed and there's no memory buffer to go back to.

    Instead what you need to do is to use a different command. If you can get the Dir command to eliminate empty directories from the list then that is ideal. Another way (this is theory at this point) is to get the Dir command to somehow make each line the same and (perhaps) include the file total in each line. Then you can act on each line with FindStr, without regards to any other line.

    So how does this work out with the commands?

    When I looked at the Dir command, the optimal syntax appears to be:

    Dir *.* /s /b
    The problem is that my testing shows this included empty folders. Nor is there a way to combine file size information with the Bare (/b) option. The Tree command is no better (there is a way for the Tree command to list files).

    If you are willing to download a Windows version of the Unix "ls" command, it might be possible to do it that way. I believe you are looking for some variation of the following:

    ls -R -A -1 *.*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •