View Full Version : DOS problem

Citizen Bleys
11-20-2001, 08:33 PM
Anybody know how to test if a replaceable parameter is a directory? if exist %1 returns true only if %1 is a <i>file</i>, not a directory.

I need to write a batch file that reacts differently if %1 represents a null, a file, a directory, or anything else (i.e., if it's not "", and it's not a file or directory, it creates a new direcotory named %1)

Also, anybody know how to extract filenames from a dir statement? I have to write another batch file which uses TYPE to display the contents of all read-only files.

if "%1" == "" goto end
type %1
goto startloop


11-22-2001, 09:17 AM
For the directory vs file thing, I can only think to try cd %1 and test for an errorlevel.

I don't think DOS supported any sort of regular expressions or output manipulation. I'd just as soon try it in C.

In newer DOS versions, dir /b will show filenames plain, 1 per line. Type dir /? for details.

Citizen Bleys
11-22-2001, 08:36 PM
It's for school. We're not allowed to use real programming languages in the "batch files" section :(

Dr Unne
11-25-2001, 06:37 AM
I don't know of any batch command that'd let you check a parameter for filetype / directory. Why would you want to? Is it some sort of assignment?

You can use DOSKEY to create a macro to overload what certain commands do, I think. Like you could overload "dir" to always mean "dir /s /w" or something. It's a way people used to save time, by not having to type all the commonly used switches every time they used a command. You could write a batch file that loads all the DOSKEY macros you need. I don't know if that helps. It's been awhile since I tried anything like that.

Citizen Bleys
11-25-2001, 08:35 AM
Yeah, it was for a school assignment. But never mind, I passed that module, with honors, I think, even though I slaiked that assignment.

After using bash, I don't like DOS as much as I used to. DOSKEY is fine, but bash does all that without having to load a TSR. Yes, including macros. (alias lw='ls -F' is a good one)