龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

利用API创建文件目录

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
PrivateDeclareFunctionCreateDirectoryLib"kernel32"Alias"CreateDirectoryA"(ByVallpPathNameAsString,lpSecurityAttributesAsSECURITY_ATTRIBUTES)AsLong PrivateTypeSECURITY_ATTRIBUTES nLengthAsLong lpSecurityDescriptorAsLong bInheritHandleAsLong E
PrivateDeclareFunctionCreateDirectoryLib"kernel32"Alias"CreateDirectoryA"(ByVallpPathNameAsString,lpSecurityAttributesAsSECURITY_ATTRIBUTES)AsLong
  
  PrivateTypeSECURITY_ATTRIBUTES
  nLengthAsLong
  lpSecurityDescriptorAsLong
  bInheritHandleAsLong
  EndType
  
  SubMain()
  '在C盘创建了"VB编程乐园"目录
  CallCreateNewDirectory("C:VB编程乐园")
  MsgBox"在C盘创建了VB编程乐园目录"
  EndSub
  
  PublicSubCreateNewDirectory(NewDirectoryAsString)
  DimsDirTestAsString
  DimSecAttribAsSECURITY_ATTRIBUTES
  DimbSuccessAsBoolean
  DimsPathAsString
  DimiCounterAsInteger
  DimsTempDirAsString
  DimiFlagAsInteger
  iFlag=0
  sPath=NewDirectory
  
  IfRight(sPath,Len(sPath))<>""Then
  sPath=sPath&""
  EndIf
  
  iCounter=1
  DoUntilInStr(iCounter,sPath,"")=0
  iCounter=InStr(iCounter,sPath,"")
  sTempDir=Left(sPath,iCounter)
  sDirTest=Dir(sTempDir)
  iCounter=iCounter 1
  
  '创建目录
  
  SecAttrib.lpSecurityDescriptor=&O0
  SecAttrib.bInheritHandle=False
  SecAttrib.nLength=Len(SecAttrib)
  bSuccess=CreateDirectory(sTempDir,SecAttrib)
  Loop
  EndSub->

精彩图集

赞助商链接