How to? Use EXCEPT on files without subdirectories?

Feb 23, 2012
238
3
#1
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?
 
Feb 23, 2012
238
3
#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?
 

rconn

Administrator
Staff member
May 14, 2008
10,533
94
#4
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?
Nope, because file exclusion ranges do allow specifying specific directories to exclude.
 
Feb 23, 2012
238
3
#5
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.

Nope, because file exclusion ranges do allow specifying specific directories to exclude.
 
Feb 23, 2012
238
3
#6
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.
 
Feb 23, 2012
238
3
#9
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.
 

rconn

Administrator
Staff member
May 14, 2008
10,533
94
#10
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").
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.