Solved

Reading/Delete files and directories

Posted on 2002-04-03
4
175 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
4 Comments
 
LVL 1

Accepted Solution

by:
freg earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now