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

How to? Use EXCEPT on files without subdirectories?

Discussion in 'Support' started by Avi Shmidman, Mar 10, 2012.

  1. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    In my first attempts to use EXCEPT, I noticed that it hides not only files from execution, but also subdirectories. (I didn't expect this behavior, because the documentation refers to the parameters as containing "the file or files to exclude from the command", without mentioning subdirectories, and thus I thought at first that an "except (*.*)" command would exclude only the files in the directory, but would include the subdirectories).
    I wonder then: Is there a way to instruct EXCEPT to exclude all files but to leave the subdirectories alone?
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,869
    Likes Received:
    83
    You could use a size range, but it's unlikely that you actually want to (or should) use EXCEPT, which is an obsolete holdover from the 4DOS days (and only preserved for the sake of compatibility with old batch files).

    Let us know what you're trying to do, and we can suggest a more suitable alternative.
     
  3. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    Hi Rex,

    As I just posted in an alternate thread, I'm trying to "flatten" the file structure of a folder [that is: I have a base directory containing some files, plus a few subdirectories, each with a few files, and I'd like to bring all of the files from the subdirectories into the base directory. "move /sx *.* ." doesn't work because it fails on the files in the base directory, and it cannot be combined with /S+1. I now tried: "except (*.*) move /sx *.* .", but that didn't work either, because EXCEPT hid the directories, too].
    However, taking my cue from EXCEPT, with its method of hiding files to exclude them, I've now settled on the following batch sequence:
    attrib *.* +h
    move /sx *.* .
    attrib *.* -h

    You've stated, though, that it is "unlikely that you actually want to (or should) use EXCEPT", and presumably your statement would apply to the batch file I've proposed as well. So, what would you propose instead? And, what is the downside of using the hidden attribute in this manner (other than the minor negative side effect of unhiding previously hidden files in the base directory?)

    In general, although the docs recommend using "File exclusion ranges" rather than "EXCEPT", it seems to me that EXCEPT can provide a good deal of flexibility that File Exclusion Ranges do not. Specifically, EXCEPT allows specification of a list of specific directories to exclude, while File Exclusion Ranges do not. So, for cases in which specific directories should be excluded, do you still recommend using EXCEPT?
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,869
    Likes Received:
    83
    Nope, because file exclusion ranges do allow specifying specific directories to exclude.
     
  5. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    Ah, OK, I see now that I can exclude directories by appending a "\".
    However, it seems that I cannot exclude the current directory. Thus, if I write:
    [c:\temp] dir /[!c:\temp\] *.* /s
    It still shows me all of the files in c:\temp.

     
  6. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    In fact, as far as I can tell, the Exclusion Ranges can't take absolute paths at all; for instance, I have a directory r:\temp\ which has a number of directories such as folder1, folder2, folder3, etc.
    If I write:
    [r:\temp] dir /[!folder3\] *.* /s /b
    Then folder3 and its files are excluded.
    However, if I write:
    [r:\temp] dir /[!r:\temp\folder3\] *.* /s /b
    Then folder3 and its files are displayed, and the exclusion list seems to have no effect.

    If this is the case, EXCEPT still has an important advantage, because it allows specification of full paths.
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,869
    Likes Received:
    83
    No, you can't use paths in exclusion ranges. But you don't need to; just enter the directory names. (There's no advantage in using full paths in EXCEPT, since it cannot handle subdirectories anyway.
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,869
    Likes Received:
    83
    Use /S+1.
     
  9. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    Hi Rex,
    1] OK, I didn't realize that EXCEPT can't handle subdirectories further down the line (the documentation seemed to indicate that this would work, since it states: "EXCEPT will assume that the files to be excluded are in the current directory, unless another directory is specified explicitly").
    2] Nevertheless, I think that the ability to specify a full path in Exclusion Ranges is significant, since in many cases I have more than one directory by the same name in a large tree of directories, and in order to exclude only one of them from a large scale "/S" operation I need to be able to specify the full path.
    3] Finally, back to the main issue. I am aware that I can use "/S+1" to perform a "dir" without the current directory; however, the problem is that I can't use it together with a "move /SX" command. I used the "dir" commands above just to illustrate the problem that Exclusion Ranges cannot be used to exclude the files in the current directory. But the goal I was aiming for was to find a way to use Exclusion Ranges to execute a "move /SX" while ignoring the files in the current directory.
     
  10. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,869
    Likes Received:
    83
    That means that you can specify a full pathname in the exclude list to hide a file in a subdirectory; it does *not* mean that EXCEPT will step into and run a command in that directory.

    But it would be a lot easier and faster to do it with ATTRIB.
     
  11. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Avi, problem completely solved and easily. Please see my posting in the other thread. - Dan
     

Share This Page