How to? Use EXCEPT on files without subdirectories?

Feb 23, 2012
240
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?
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
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.
 
Feb 23, 2012
240
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
12,345
150
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
240
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.

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

rconn

Administrator
Staff member
May 14, 2008
12,345
150
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.
 
Similar threads
Thread starter Title Forum Replies Date
N Except chokes on files with right parens Support 4
vefatica WAD EXCEPT? Support 9
CWBillow File Lists with EXCEPT command Support 7
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
fpefpe How to? shortcuts and batch files Support 4
C v28 key files Support 2
J ffind does not find files Support 4
C duplicate files in multiple plugin sites Support 9
Dmitry L. Kobyakov Fixed The SETARRAY /R command works incorrectly with cyrillic files Support 2
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
vefatica FFIND, temp files? ... not deleted? Support 0
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
vefatica Tmp files from in-process pipes not deleted Support 6
vefatica Finding files with alternate data streams? Support 4
rps Multi-column DIR /v not displaying all files. Support 5
D How to skip files in a fileset? Support 6
vefatica PIPEVIEW leaves TMP files Support 18
K "copy /z /w" command not deleting read-only files in destination Support 10
Jesse Heines "Taken" date for JPG and PNG files Support 4
O I cannot use links to .btm files Support 5
C How to? rename files with spaces Support 8
R How to? Append files in multiple subfolders using copy? Support 8
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
vefatica Find Files/Text dialog: does it work? Support 0
Joe Caverly UNZIPping older .ZIP files Support 3
C Documentation default location for LOG files Support 21
P exit /b in batch files Support 7
P Labels in batch files: TCC vs CMD.exe Support 9
M ANSI is used to show files instead of OEM in version 17 to 19 ! Support 5
C 7Z files on forum? Support 0
x13 Problem listing repository files using DIR http(s)://... Support 8
B Can copy command concatenate multiple mp3 files Support 2
redwdc Copying files with spaces, commas, etc. Support 5
J New lexer for TCC batch files. Support 0
M How to? want to download a file from a website enumarate the links and download the files Support 2
keithg1964 TCC RT Install Files Support 1
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
thorntonpg Handling files with embedded spaces Support 1
WavSlave Fixed Unable to sort files by description in TCC v19 Support 2
P Files older - exist Support 1
D safe delete files command Support 10
P Copying files in subdirectories Support 9
C WAD VIEW print multiple files - switches fail Support 10
MikeBaas How to? SELECT: exclude files / display prompt Support 2
Phileosophos WAD Can't rename files in subfolders Support 1
nickles WAD del unable to delete files ending in "." Support 18
P Rename files with ampersand in the name Support 1
C Touch command — I Need to touch matching files in another directory. Support 5
S iftp copying pgp files from ftp is not working Support 11

Similar threads