e.g..
Kill ("C:\MyTrash")
how can i check that that directory folder exsts, and if it does, the delete the folder and its contents.. ?
Printable View
e.g..
Kill ("C:\MyTrash")
how can i check that that directory folder exsts, and if it does, the delete the folder and its contents.. ?
The DIR() function.
VB Code:
Option Explicit Private Sub Form_Load() Dim st st = Dir("d:\temp", vbDirectory) If Len(st) > 0 Then MsgBox "Exists!" ' or kill it End Sub
ok thanks and in terms of lettercase, is
Kill ("C:\Hello") same as Kill ("C:\HELLO") ?
Yes, it is!
VB Code:
Option Explicit Private Sub Form_Load() Dim st st = Dir("d:\tEmp", vbDirectory) If Len(st) > 0 Then MsgBox "Exists!" End Sub
this is giving me error saying file not found and the folder tt is there
VB Code:
Private Sub Command1_Click() Dim st1 st1 = Dir("C:\Documents and Settings\Home\My Documents\tt", vbDirectory) If Len(st1) > 0 Then Kill "C:\Documents and Settings\Home\My Documents\tt" End If End Sub
You can convert it to a short file name...
http://vbforums.com/attachment.php?attachmentid=36291
is that why it keeps returning 'file not found' because
C:\Documents and Settings\Home\My Documents\tt
is too long name? :confused:
Probably because of the spaces in it, which the zip will convert.
i tested it for one without spaces in it, still doesnt work.. gives file not found error :confused:
VB Code:
Private Sub Command1_Click() Dim st1 st1 = Dir("C:\windows\blahTestFolder", vbDirectory) If Len(st1) > 0 Then Kill "C:\windows\blahTestFolder" End If End Sub
First, you have to kill all files in the folder (use \folder\*.*) and then use RmDir to delete the folder name.
Use the file system object instead :)
It handles spaces, UNC names, and deleting directories that have files in them. Not to mention once you become comfortable with it, handling file access in VB.NET or C# will be a snap.
First include Microsoft Scripting Runtime under project->References
VB Code:
Dim fsObj As FileSystemObject Set fsObj = New FileSystemObject If fsObj.FolderExists(YourFolder) Then fsObj.DeleteFolder YourFolder, True
I was thinking abou that, after I posted.
omggg no i just tried that code and it deleted all my document folders and contents nooo man what can i do to retrieve them back?? :confused: :confused: man this is badd please someone help me
would system restore bring them back???
Holy crap. Which code deleted your "My Documents"? The only way to delete your my documents is if you told it to delete your documents.Quote:
Originally Posted by Pouncer
You can try this program http://www.winternals.com/Products/FileRestore/
it should have deleted the tt folder, but it deleted all the folders fromVB Code:
Dim myFolder As String myfolder = "C:\Documents and Settings\Home\My Documents\tt" Dim fsObj As FileSystemObject Set fsObj = New FileSystemObject If fsObj.FolderExists(myfolder) Then fsObj.DeleteFolder myfolder, True
C:\Documents and Settings\Home\My Documents
i lost almost everything man :confused:
can you show me the proper way to do it please
That is the proper way to do it. The only other thing I would add is to not use "My Documents". I personally create a directory called C:\TEMP. Then I create a subdirectory for each application "C:\TEMP\PROGRAMWHATEVER", and do all my temp work there.Quote:
Originally Posted by Pouncer