grenutze
asked on
Deleting part of directory content
I want to create v.b 6 exe which doesn't requires any dll.
The program will check if inside the directory there some essentials files are exist if some of these files are missing the directort will be delete except one directory needed in this directory.
I want my program to be efficiency and if it is possible not to move the needed directory (the subdirectory)
to other "temp" directory and the copying the directory after "cleaning" the parent directory.
I had noticed that there is a collection name folders.
Is it possible to use with the command "for each ..."
and then delete each file/directory individualy?
Can you tell me If there are other ways and how do I use them.
Thank you for your time.
The program will check if inside the directory there some essentials files are exist if some of these files are missing the directort will be delete except one directory needed in this directory.
I want my program to be efficiency and if it is possible not to move the needed directory (the subdirectory)
to other "temp" directory and the copying the directory after "cleaning" the parent directory.
I had noticed that there is a collection name folders.
Is it possible to use with the command "for each ..."
and then delete each file/directory individualy?
Can you tell me If there are other ways and how do I use them.
Thank you for your time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is my code :
-----------------
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory
If ((GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory) And (Asc(MyName) <> 46) Then
' Display entry only if it's a directory.
If (MyName <> "xxx") Then
Set Obj_folder = Obj_fso.GetFolder(MyPath & MyName)
Obj_folder.Delete True 'deleting the directory
End If
End If
MyName = Dir() ' Get next entry.
Loop
-----------------
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory
If ((GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory) And (Asc(MyName) <> 46) Then
' Display entry only if it's a directory.
If (MyName <> "xxx") Then
Set Obj_folder = Obj_fso.GetFolder(MyPath & MyName)
Obj_folder.Delete True 'deleting the directory
End If
End If
MyName = Dir() ' Get next entry.
Loop
ASKER
The dir function is very useful, i had use this function and added a loop which passes on all the folders by using the command - dir() inside the loop, and inside the loop i had deleteded all folders except of the wanted directory.