Author | Page created on | Page updated on |
Bill Thoen | 11.11.00 |
DLL calls used by this example |
Type SECURITY_ATTRIBUTES CreateDirectory32 (&16) RemoveDirectory32 (&16) |
Download available as: |
MapBasic . Copy/Paste to a new MB page if needed, or download if available. |
include "mapbasic.def"
type SECURITY_ATTRIBUTES nLength as integer 'DWORD in Windows lpSecurityDescriptor as integer 'LPVOID in Windows bInheritHandle as integer 'BOOL in Windows end type declare function CreateDirectory32 lib "Kernel32.dll" alias "CreateDirectoryA" (byval sPath as string, tSecurity as SECURITY_ATTRIBUTES) as integer declare function RemoveDirectory32 lib "Kernel32.dll" alias "RemoveDirectoryA" (byval sPath as string) as integer declare function CreateDirectory16 lib "Kernel.dll" alias "CreateDirectory" (byval szDir as string, tSecurity as SECURITY_ATTRIBUTES) as integer declare function RemoveDirectory16 lib "Kernel.dll" alias "RemoveDirectory" (byval szDir as string) as integer declare sub main declare sub CreateDir declare sub DeleteDir declare sub ExitApp '---------------------------------------------------------------------- sub main create menu "Directory Test" as "Create a directory" calling CreateDir, "Delete an empty directory" calling DeleteDir, "Exit" calling ExitApp alter menu bar add "Directory Test" end sub '---------------------------------------------------------------------- sub CreateDir dim sPath as string dim tSecurity as SECURITY_ATTRIBUTES dim nStatus as integer tSecurity.nLength = 24 'Size of this structure in bytes, but you 'can get away with using 0 in place of the 'tSecurity parameter as Win3.1 and Win95 'seem to ignore it anyway. sPath = "C:\mapinfo\CreatDir" dialog title "Create Directory" control statictext position 4,4 title "Enter a directory:" control edittext position 76,2 width 200 value sPath into sPath control OKbutton position 4,24 control CancelButton position 46,24 if not CommandInfo (CMD_INFO_DLG_OK) then exit sub end if do case SystemInfo (SYS_INFO_MIPLATFORM) case MIPLATFORM_WIN32 nStatus = CreateDirectory32 (sPath, tSecurity) case MIPLATFORM_WIN16 nStatus = CreateDirectory16 (sPath, tSecurity) case else note "This app serves only the one, true OS." nStatus = 0 end case if nStatus = 0 then note "Directory " + sPath + " not created." else note "Directory " + sPath + " created." end if end sub '---------------------------------------------------------------------- sub DeleteDir dim sPath as string dim nStatus as integer sPath = "C:\mapinfo\CreatDir" dialog title "Delete Directory" control statictext position 4,4 title "Enter a directory:" control edittext position 76,2 width 200 value sPath into sPath control OKbutton position 4,24 control CancelButton position 46,24 if not CommandInfo (CMD_INFO_DLG_OK) then exit sub end if do case SystemInfo (SYS_INFO_MIPLATFORM) case MIPLATFORM_WIN32 nStatus = RemoveDirectory32 (sPath) case MIPLATFORM_WIN16 nStatus = RemoveDirectory16 (sPath) case else note "This app serves only the one, true OS." end case if nStatus = 0 then note "Directory " + sPath + " not removed." else note "Directory " + sPath + " removed." end if end sub '---------------------------------------------------------------------- sub ExitApp 'end program terminate application "dir_bill.mbx" end sub '---------------------------------------------------------------------- |
Comments: |