[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Reading/Delete files and directories

Posted on 2002-04-03
4
Medium Priority
?
185 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 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