?
Solved

Reading/Delete files and directories

Posted on 2002-04-03
4
Medium Priority
?
184 Views
Last Modified: 2010-05-02
Friends,

I'm needing of routine that do:

* search a file inside of directory,
* read all files of directory,
* delete a directory that have files,
* create directory/file,
* rename directory/file.

Thanks for the help.

DenisPaim.

0
Comment
Question by:DenisPaim
[X]
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
4 Comments
 
LVL 1

Accepted Solution

by:
freg earned 200 total points
ID: 6915428
Add a reference to 'Microsoft Scripting RunTime"

And add this code in you project :

    Dim fsoFileObject As New FileSystemObject
    Dim strPath As String
    Dim strFile As String

    strPath = "C:\DirExample\"
    strFile = "MyFile.txt"
   
    ' Search for a file
    If Dir$(strPath & strFile) <> "" Then
        ' ...then delete the folder if the file exists
        fsoFileObject.DeleteFolder strPath, True
    End If
   
    ' Create a new folder
    fsoFileObject.CreateFolder "C:\NewDir"
   
    ' Create a new text file in the folder
    fsoFileObject.CreateTextFile "C:\NewDir\NewFile.txt"
   
    ' Rename the new folder
    Name "C:\NewDir" As "C:\NewDir2"
   
    Set fsoFileObject = Nothing
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6915536
You can use the fast internal VB commands for these:

* search a file inside of directory,
Dir$(FileToFind)
--Returns vbNullString if not found

* read all files of directory,
Dir$("Path\*.*")
--Returns the first file in the directory
Dir$
--Returns the next file in the directory; repeat until vbNullstring

* delete a directory that have files,
Kill filename
--Deletes a file; repeat until all files are removed
RmDir path
--Removes a folder/directory

* create directory/file,
MkDir Path
--Makes a directory
Open filename for output as #1
print #1,"abc";
close #1
--creates a file with contents of "abc"

* rename directory/file.
Name File1 as File2
--Renames a file
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7642903
Hi DenisPaim,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: freg and rspahitz

DenisPaim, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7673530
Moving the Question to the PAQ

kb
Experts Exchange Moderator

rspahitz your points are here
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20444949.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

752 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