Home > Software engineering >  How to delete a folder in the VB folder?
How to delete a folder in the VB folder?

Time:10-10

Note that only the folder, not the file, such as delete all the folder in the "c:/temp", but also keep the,,, how to write?

CodePudding user response:

If a folder in the file, or delete not to drop,

You mean Copy all files, delete folder?

CodePudding user response:

If the folder a folder is empty:
 Dim strDirectory As String 

On the Error Resume Next

StrDirectory=Dir (" c: \ temp \ *. * ", vbDirectory)

The Do While strDirectory & gt; "
"StrDirectory="c: \ temp " & amp; StrDirectory
The RmDir (strDirectory)
StrDirectory=Dir ()
Loop

CodePudding user response:

refer to the second floor of123 response:
if the folder a folder is empty:
 Dim strDirectory As String 

On the Error Resume Next

StrDirectory=Dir (" c: \ temp \ *. * ", vbDirectory)

The Do While strDirectory & gt; "
"StrDirectory="c: \ temp " & amp; StrDirectory
The RmDir (strDirectory)
StrDirectory=Dir ()
Loop



The forehead, and a folder in file even ribbon folder all deleted, in c:/temp file does not delete the


Internet to this, but I do not know to have said effects, and can be forced to delete? If I have a window opened a folder, hope can be forced to delete,,,


 Set fs=CreateObject (" Scripting. FileSystemObject ") 
Fs. Deletefile deleting files
Fs. Deletefolder
Delete the folder
3: use the API can also do
Declare the Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Deletefile filename 'forced to delete a file




CodePudding user response:

refer to the second floor of123 response:
if the folder a folder is empty:
 Dim strDirectory As String 

On the Error Resume Next

StrDirectory=Dir (" c: \ temp \ *. * ", vbDirectory)

The Do While strDirectory & gt; "
"StrDirectory="c: \ temp " & amp; StrDirectory
The RmDir (strDirectory)
StrDirectory=Dir ()
Loop


I ran this, but didn't succeed, not to delete a folder,,,

CodePudding user response:

refer to the second floor of123 response:
if the folder a folder is empty:
 Dim strDirectory As String 

On the Error Resume Next

StrDirectory=Dir (" c: \ temp \ *. * ", vbDirectory)

The Do While strDirectory & gt; "
"StrDirectory="c: \ temp " & amp; StrDirectory
The RmDir (strDirectory)
StrDirectory=Dir ()
Loop


I tried to use the fs can,,, but there is a problem, if the traverse to the child folder file is set to read-only can not delete off, ask the name of different read-only folder (including inside a folder) how to remove the read-only?

  • Related