[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Reading/Delete files and directories

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
DenisPaim
Asked:
DenisPaim
1 Solution
 
fregCommented:
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
 
rspahitzCommented:
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
 
DanRollinsCommented:
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
 
kodiakbearCommented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now