Visual Basic, .NET, ASP, VBA, VBScript
 
  Библиотека кодов  
  Работа с файлами/директориями  
     
  Три пути создания папки  
  Разместите на форме элемент CommandButton
'1 ВАРИАНТ

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Public Sub CreateNewDirectory(NewDirectory As String)
Dim sDirTest As String
Dim SecAttrib As SECURITY_ATTRIBUTES
Dim bSuccess As Boolean
Dim sPath As String
Dim iCounter As Integer
Dim sTempDir As String
iFlag = 0
sPath = NewDirectory
If Right(sPath, Len(sPath)) <> "\" Then
sPath = sPath & "\"
End If
iCounter = 1
Do Until InStr(iCounter, sPath, "\") = 0
iCounter = InStr(iCounter, sPath, "\")
sTempDir = Left(sPath, iCounter)
sDirTest = Dir(sTempDir)
iCounter = iCounter + 1
'create directory
SecAttrib.lpSecurityDescriptor = &O0
SecAttrib.bInheritHandle = False
SecAttrib.nLength = Len(SecAttrib)
bSuccess = CreateDirectory(sTempDir, SecAttrib)
Loop
End Sub

Private Sub Form_Load()
Call CreateNewDirectory("c:\123\456\789\")
End Sub

'2 ВАРИАНТ


Private Declare Function MakeSureDirectoryPathExists Lib "IMAGEHLP.DLL" (ByVal DirPath As String) As Long
Sub CreateFolder(ByVal DestPath As String)
If Right(DestPath, 1) <> "\" Then DestPath = DestPath & "\"
If MakeSureDirectoryPathExists(DestPath) = 0 Then
MsgBox "Ошибка в создании папки: " & DestPath
End If
End Sub
Public Function FileName(FilePath As String)
Dim strArray() As String
strArray = Split(FilePath, "\")
FileName = strArray(UBound(strArray))
End Function
Private Sub Form_Load()
CreateFolder ("c:\123\456\789")
End Sub

'3 ВАРИАНТ


Private Sub Command1_Click()
On Error GoTo errorfolder:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateFolder "c:\new_folder"
errorfolder:
If Err = 58 Then MsgBox "File already exists"
Exit Sub
End Sub
 
     
  VBNet online (всего: 52050)  
 

Логин:

Пароль:

Регистрация, забыли пароль?


В чате сейчас человек
 
     
  VBNet рекомендует  
   
     
  Лучшие материалы  
 
ActiveX контролы (112)
Hitman74_Library (36119)
WindowsXPControls (20739)
FlexGridPlus (19374)
DSMAniGifControl (18295)
FreeButton (15157)
Примеры кода (546)
Parol (18027)
Passworder (9299)
Screen saver (7654)
Kerish AI (5817)
Folder_L (5768)
Статьи по VB (136)
Мое второе впечатление... (11236)
VB .NET: дорога в будущее (11161)
Основы SQL (9225)
Сообщения Windows в Vi... (8788)
Классовая теория прогр... (8619)
 
     
Техническая поддержка MTW-хостинг | © Copyright 2002-2011 VBNet.RU | Пишите нам