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
Solved

Reading/Delete files and directories

Posted on 2002-04-03
4
181 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

828 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