Deleting part of directory content

Posted on 2003-02-25
Medium Priority
Last Modified: 2010-05-01
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.

Question by:grenutze
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

XpGautham earned 150 total points
ID: 8016277

Try Using DIR Function

if dir("Path",vbdirectory") <> "" then
  if dir(""path\file") <> "" then
  end if
end if

u can Copy a file from one folder to another by Using FileCopy Function

Author Comment

ID: 8019515
Thanks for the advise.
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.

Author Comment

ID: 8024490
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.

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question