Solved

Mysterious Directory in DOS - Part II

Posted on 1998-10-14
6
513 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:StMeyer
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now