Solved

Mysterious Directory in DOS - Part II

Posted on 1998-10-14
6
522 Views
Last Modified: 2012-06-21
Hi!

The question I pose is more DOS than Pascal related but as there is no explicit DOS section I guess here might be the best place to ask it (hope that's ok). I did already pose it somewhere else a few months ago but as I was new to Experts Exchange I made a mistake by accepting an answer too soon which was incomplete (-:

There is a chess program for DOS named "Rebel" (version is 7.0). This chess program was able to create a directory in my DOS/Win 3.1 file system named "Ax nf zz"!!!
As I know it's not allowed in DOS/Win 3.1 to create a directory whose name contains spaces. If I try i.e. to do it by typing "MKDIR C:\Ay dd" I get an error message like "too many parameters ...dd".

I have two questions now:

1. How is it possible to create such an "illegal" directory in a DOS/Win 3.x file system?

2. How can I access such a directory THROUGH DOS ("CD Ax nf zz" does not work!)?

Wizard needed!

StMeyer
0
Comment
Question by:StMeyer
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1215792
The only reason you cannot create or change to a directory from the dos command line is because of the way dos commands handle parameters.  To dos commands, the separator between parameters is a space.  It thinks you are entering several parameters instead of one.  However, it is LEGAL, and it is POSSIBLE to create a directory with spaces.

To do this programmatically in Pascal, you just use the MkDir command.  This is a string enlcosed within quotes, so spaces are taken literally.  The following program will create a directory named ax nf zz:


program md2;

uses dos;

var
   s :string;

begin
 s := 'ax nf zz';
 MkDir(s);
end.


You can access the directory programmatically using the ChDir command.  The cd command from the command line won't work, however.  Here is a modified version of the cd command that you can use to access directories with spaces, from the command line:

program cd2;

uses dos;

var
   s :string;
   i :integer;

begin
 for i := 1 to ParamCount do s := s + ParamStr(i) + ' ';
 s[0] := chr(length(s)-1);
 ChDir(s);
end.

Compile this to disk.

To use this from the dos command line, for the directory ax nf zz, you would type:

cd2 ax nf zz

and then you will be transferred to the ax nf zz directory.  The cd2 command works like the cd command, except that if spaces are found, they are treated as separate parameters.  If there is more than one parameter, the program concatenates them to form one directory, with the spaces included.  However, this will not work with 2 or more spaces in a row, as any extra spaces are ignored.  For example, if you typed

cd2 ax     nf zz

this would still take you to the ax nf zz directory.

If you do not have a pascal compiler to compile this, I would be happy to send you the .exe version of this command if you leave me your e-mail address.


0
 

Author Comment

by:StMeyer
ID: 1215793
Hi scrapdog,

thank you very much for your answer - very good!

'Code begins
MKDIR "ax" + " " + "nf" + " " + "zz"
CHDIR "ax" + " " + "nf" + " " + "zz"
SHELL 'control where we are now
'Code ends

What's this??? - you may ask. Well, the first line is program md2 but not for Pascal, it' s for - ehm - (ok I must say it now even though I did not want to) Quick Basic. Thanks to you I was able to find out this form which can not be found in any handbook. The second line is a first step to rewrite program cd2 to Basic but I think ParamCount (I guess it returns the number of command line parameters - right?) has no equivalent in Basic. In case you are a Basic Wizard, too, please give me a hint (or do you know if I can put Pascal code - like Assembly - into Basic somehow?).
Don't worry! I intend to give you the points anyway, as you deserve them for your help. I' m just curious if you know some Basic (I still like it even though I know Pascal is more powerful). Unfortunately I don't have time to rewrite this into Pascal or any other language (one of my first programs):

ftp://ftp.cdrom.com/pub/simtelnet/msdos/dirutl/ttrack21.zip

By the way, there's a trick I use in my program for Windows 95 - DOS 7.0 (I guess): CD ax nf zz - does not work
                   CD "ax nf zz" - works!
Did you know this?

Best regards

Stephan

P.S.: I can compile your code. Nevertheless thank you very much for the friendly offer to do it for me. Hope to hear from you once again soon.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215794
The last experience I had with BASIC (other than a little bit of Visual Basic) was the BASIC V2 found in the ROM of a Commodore 64.  In other words, I know bare bones ANSI (or even less) BASIC.

As far as your question about an equivalent to paramcount in BASIC, my guess would be no.  Unless your interpreter compiles your BASIC programs into .exe files or .com files, you can't call them on the command line, so there would be no way to include parameters.  Then again, I could be wrong.  In my experience, all BASIC was interpreted, rather than compiled.  However, if you use Visual Basic, there may be an equivalent to ParamCount, if you check the docs or help files for anything to do with command-line parameters.

Your question about Pascal code in BASIC is a definite no.  BASIC and Pascal are two very different languages.  Assembly language is not a part of Pascal, it is independent of Pascal, and I am pretty sure there are ways to incorporate assembly language routines into BASIC, but I don't think it is as easy as including it inline like you can in Pascal.  And I am not sure how you would do it.

As for cd "ax nf zz", I did not know that, because I have never come across a directory with spaces.  But I suppose this would be the first logical choice to try out if I ever had encountered one.

 
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:StMeyer
ID: 1215795
Thank you scrapdog! I'm quite optimistic now I can find the last step to debug my QBasic program.

Best regards

Stephan
0
 

Expert Comment

by:ewolfman
ID: 1215796
Hi,

I have a different solution to your problem. In my opinion, your
directory is (or could be) not a name including spaces at all, but the ASCII character 255. This character is blank, and yet it is valid for the MD, CD and RD commands, and acts as a regular name like all others. You can type this character onto the prompt (and in your pascal programs) by pressing Alt, clicking the ASCII character you want (i.e. 255) and release Alt. Again:
You will not see this character, but trust me: It is no blank !
(By the way, ASCII for blank is 32).

Wolfman
0
 

Author Comment

by:StMeyer
ID: 1215797
Hi Wolfman,

thank you for sharing your idea! If I open a DOS box in Win95 and type

CD "c:\ax nf zz"

using two spaces I can access the directory created by the chess program Rebel. If I do the same (no matter if with "" or without it) while using ASCII character 255 I get an error message ("invalid directory"). I mean this shows that the directory name (in that case) in fact includes spaces.
However, it's interesting to know that there's theoretically another possible explanation, so I'm glad you added the comment.

Thanks again and best regards

Stephan
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This problem is more common than not and I will show you some things to check to solve this problem.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question