CyberCarsten
Jan 21st, 2000, 06:20 AM
Hi all!
I have 2 questions...
1. How can i create a file via an InputBox, and display and error if the file already exists?
2. How can i delete a selected folder in a DirListBox??
------------------
Yours sincierly
CyberCarsten http://home18.inet.tele.dk/cyber/
carsten.h.thomsen@mail.tele.dk
[This message has been edited by CyberCarsten (edited 01-21-2000).]
JeffSM
Jan 21st, 2000, 09:20 PM
I'm sending you this project:
Option Explicit
'
'WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!
'
' THE FOLDER THAT YOU WANT DELETE MUST BE SELECTED WITH DOUBLE CLICK!
'
'WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!WARMING!
Private Sub cmdDelete_Click()
If Dir1.Path = "C:\" Then
MsgBox "You can't delete C:\", vbCritical, "Warming!"
Exit Sub
End If
If MsgBox("Do you really want delete: " & Dir1.Path, vbYesNo) = vbNo Then Exit Sub
Dim cUp As String
Dim nPos As Long
For nPos = Len(Dir1.Path) To 1 Step -1
If Mid$(Dir1.Path, nPos, 1) = "\" Then
Exit For
End If
Next
cUp = Mid$(Dir1.Path, 1, nPos - 1)
'Shell "DELTREE /Y " & Chr(34) & Dir1.Path & Chr(34), vbHide
On Error Resume Next
'This 'll not kill sub folders!
'If your folder has sub folders you'll need add extra code.
VBA.FileSystem.Kill Dir1.Path & "\*.*"
VBA.FileSystem.RmDir Dir1.Path
DoEvents
DoEvents
Dir1.Path = cUp
Dir1.Refresh
End Sub
Private Sub Command1_Click()
Dim cFile As String
Dim lUserCanceled As Boolean
cFile = "C:\New.txt"
TrapBegin:
cFile = InputBox("Type a valid file name:", "Creating files", cFile)
If cFile = "" Then
If lUserCanceled Then Exit Sub
MsgBox "File name invalid!", vbExclamation
lUserCanceled = True
GoTo TrapBegin
Else
lUserCanceled = False
'If the user can't type the path
'you 'll nedd verify "\" and "/" and ":" to avoid errors!
If InStr(1, cFile, "*") <> 0 Or _
InStr(1, cFile, "?") <> 0 Or _
InStr(1, cFile, "|") <> 0 Or _
InStr(1, cFile, ">") <> 0 Or _
InStr(1, cFile, "<") <> 0 Or _
InStr(1, cFile, Chr(34)) Then
MsgBox "The file name can't have: * ? | < > "" : ", vbInformation
Exit Sub
End If
If Not FileExist(cFile) Then
Dim nFreeFile As Long
nFreeFile = FreeFile
Open cFile For Append As nFreeFile
Print nFreeFile, "By Jefferson"
Close nFreeFile
Else
'File Not Exist
MsgBox "This file already exist!", vbInformation
lUserCanceled = True 'If you do this it 'll not show me message "File name invalid!", when you cancel!
GoTo TrapBegin
End If
End If
End Sub
Private Function FileExist(ByVal cPathFile As String) As Boolean
On Error Resume Next
If Len(cPathFile) Then FileExist = Len(Dir(cPathFile, vbNormal + vbHidden)) > 0
End Function
Private Sub Command2_Click()
Unload Me
End Sub
Boa sorte!
Jefferson
Juan Carlos Rey
Jan 22nd, 2000, 08:54 AM
Do you mean "WARNING"?
------------------
I wish I was patient... RIGHT NOW!