When using windows cmd.exe, if we want to know whether an existing File System Object(FSO) is a file or a directory, all we have to do, is to append a BackSlash at the end of the object name and then check for its existence:
But unfortunately the above code does not work correctly under tcmd/tcc. It always echos "This is a directory".
Note that I'm already aware of ISFILE and ISDIR condition expressions, But consider the situation when we need a simple batch file that does not have to incorporate the advanced features of tcmd and also, we want to be able to run the batch file under both cmd and tcmd comspecs. We simply fail to achieve that purpose if we need to perform that very basic and common query about an FSO.
I don't think this can be considered a bug, but a matter of interpretation that is incompatible(unnecessarily maybe?) with windows cmd.
So I have a couple of questions regarding this issue:
1. Is this behavior intentional or is it something that was missed?
2. If the latter, could it expected to be fixed(bug?) or be made compatible with cmd in future versions?
3. If the former, what would be a recommended/reliable method to detect the comspec (cmd/tcmd) at batch run time and choose the execution path accordingly?
Code:
if exist example (
if exist example\ (
echo This is a directory
)else (
echo This is a file
)
)
But unfortunately the above code does not work correctly under tcmd/tcc. It always echos "This is a directory".
Note that I'm already aware of ISFILE and ISDIR condition expressions, But consider the situation when we need a simple batch file that does not have to incorporate the advanced features of tcmd and also, we want to be able to run the batch file under both cmd and tcmd comspecs. We simply fail to achieve that purpose if we need to perform that very basic and common query about an FSO.
I don't think this can be considered a bug, but a matter of interpretation that is incompatible(unnecessarily maybe?) with windows cmd.
So I have a couple of questions regarding this issue:
1. Is this behavior intentional or is it something that was missed?
2. If the latter, could it expected to be fixed(bug?) or be made compatible with cmd in future versions?
3. If the former, what would be a recommended/reliable method to detect the comspec (cmd/tcmd) at batch run time and choose the execution path accordingly?
Last edited: