Directory management -- first pass

Stephen Pope stp at create.ucsb.edu
Thu Apr 8 16:44:08 UTC 1999


Here are some system extensions in response to my query about directory manipulation. 
At the moment, I can't compile a new VM to test the primitive, do any Mac (or other 
platform) VM makers have the time to look this over.


'From Squeak 2.3 of January 14, 1999 on 08 April 1999 at 5:55:08 am'!

!FileDirectory methodsFor: 'testing' stamp: 'stp 04/08/1999 05:39'!
fileExists: filenameOrPath
        "Answer true if a normal file of the given name exists. The given name may be either a 
        full path name or a local file within this directory."
        "FileDirectory default fileExists: 'Nomad:Squeak:2.3' "
        "FileDirectory default fileExists: 'Nomad:Squeak:2.x' "
        "FileDirectory default fileExists: 'Nomad:Squeak:2.3:ReadMe.txt' "

        | dir fname |
        FileDirectory splitName: filenameOrPath to:
                [:filePath :tail |
                        fname := tail.
                        filePath isEmpty
                                ifTrue: [  "file in this directory"
                                        dir := FileDirectory default]
                                ifFalse: [  "file has its own path"
                                        dir := FileDirectory on: filePath]].
        ^dir fileNames includes: fname! !

!FileDirectory methodsFor: 'testing' stamp: 'stp 04/08/1999 05:38'!
directoryExists: filenameOrPath
        "Answer true if a directory of the given name exists. The given name may be either a 
        full path name or a local file within this directory."
        "FileDirectory default directoryExists: 'Nomad:Squeak:2.3' "
        "FileDirectory default directoryExists: 'Nomad:Squeak:2.x' "
        "FileDirectory default directoryExists: 'Nomad:Squeak:2.3:ReadMe.txt' "

        | dir fname |
        FileDirectory splitName: filenameOrPath to:
                [:filePath :tail |
                        fname := tail.
                        filePath isEmpty
                                ifTrue: [  "file in this directory"
                                        dir := FileDirectory default]
                                ifFalse: [  "file has its own path"
                                        dir := FileDirectory on: filePath]].
        ^dir directoryNames includes: fname! !

!FileDirectory methodsFor: 'testing' stamp: 'stp 04/08/1999 05:36'!
fileOrDirectoryExists: filenameOrPath
        "Answer true if a file or directory of the given name exists. The given name may be either a 
        full path name or a local file within this directory."
        "FileDirectory default fileOrDirectoryExists: 'Nomad:Squeak:2.3' "
        "FileDirectory default fileOrDirectoryExists: 'Nomad:Squeak:2.x' "
        "FileDirectory default fileOrDirectoryExists: 'Nomad:Squeak:2.3:ReadMe.txt' "

        | dir fname |
        FileDirectory splitName: filenameOrPath to:
                [:filePath :tail |
                        fname := tail.
                        filePath isEmpty
                                ifTrue: [  "file in this directory"
                                        dir := FileDirectory default]
                                ifFalse: [  "file has its own path"
                                        dir := FileDirectory on: filePath]].
        ^dir includesKey: fname! !

------ New Prim for directory delete --------

C Source -- put in sqMacDirectory.c

int dir_Delete(char *pathString, int pathStringLength) {
        /* Delete the existing directory with the given path. */
        Str255 name;
        HParamBlockRec pb;
        int okay, newRefNum, newVolNum;
        int i;

        for (i = 0; i < pathStringLength; i++) {
                name[i] = pathString[i];
        }
        name[i] = 0;
        okay = lookupPath(pathString, pathStringLength, &newRefNum, &newVolNum);
        c2pstr((char *) name);

        pb.fileParam.ioNamePtr = name;
        pb.fileParam.ioVRefNum = newVolNum;
        pb.fileParam.ioDirID = newRefNum;
        return PBHDeleteSync(&pb) == noErr;
}

--- ST source

'From Squeak 2.3 of January 14, 1999 on 08 April 1999 at 6:00:06 am'!

!Interpreter methodsFor: 'file primitives' stamp: 'stp 04/08/1999 05:59'!
primitiveDirectoryDelete
        "Delet the directory whose name's on the top of the stack."

        | dirName dirNameIndex dirNameSize |
        dirName _ self stackTop.
        self success: (self isBytes: dirName).
        successFlag
                 ifTrue: [dirNameIndex _ dirName + BaseHeaderSize.
                                dirNameSize _ self lengthOf: dirName].

        successFlag
                ifTrue: [self success: (self cCode: 'dir_Delete((char *) dirNameIndex, dirNameSize)')].
        successFlag
                ifTrue: [self pop: 1].  "pop dirName; leave rcvr on stack"! !


'From Squeak 2.3 of January 14, 1999 on 08 April 1999 at 6:01:26 am'!

!Interpreter class methodsFor: 'initialization' stamp: 'stp 04/08/1999 06:01'!
initializePrimitiveTable
        "This table generates a C switch statement for primitive dispatching."

.... insert the following in the right place

                (163 primitiveDirectoryDelete)
                (164 168 primitiveFail)

---------------------------------

stp

  Stephen Travis Pope
  stp at create.ucsb.edu      http://www.create.ucsb.edu/~stp/





More information about the Squeak-dev mailing list