How to handle files in VB?

Status
Not open for further replies.

siriusb

Cyborg Agent
You can do those things and more to a file/folder/drive easily using the File System Object model. To enable that, go Project->References and check "Microsoft Scripting Runtime". Now you can do any thing with the files and folders. Example,
Code:
Dim fso As New FileSystemObject

fso.CopyFile "c:\syslog.txt", "d:\", True
fso.CreateFolder "d:\new folder"
fso.MoveFile "c:\rubbish.txt", "d:\"
fso.DeleteFile "d:\rubbish.txt", True

Set fso = Nothing
 

Eager_Beever

Broken In
naikosen, to execute ANY DOS commands within VisualBasic code, try the following :

varX = Shell("Command.com /c <place the full DOS command here>", vbMinimizedFocus)

e.g.

varX = Shell("Command.com /c Type D:\Reports\Bill.Txt", vbMinimizedFocus)
 

Eager_Beever

Broken In
naikosen, to execute ANY DOS commands within VisualBasic code, try the following :

varX = Shell("Command.com /c <place the full DOS command here>", vbMinimizedFocus)

e.g.

varX = Shell("Command.com /c Type D:\Reports\Bill.Txt", vbMinimizedFocus)
 
OP
N

naikosen

Broken In
Is there any way to delete a locked file?
What is the best way to search a file?
Rar file can delete even a locked file before extraction.
 

siriusb

Cyborg Agent
Is there any way to delete a locked file?
I've never tried deleting a locked file. You will want to run your program before windows starts to delete such files. But there's a VC++ example for a forcedel at codeguru.com that claims to do it. Maybe you can port it VB.

What is the best way to search a file?
Like I said, use one of these methods:
1. Use the SearchPath API
2. Use the FindFirstFile with the FindNextFile APIs
3. Use the built-in Dir() function
4. Use the Drivelistbox, Dirlistbox and Filelistbox controls to walk through each directory in every drive to find the file.
5. Use the FSO drives,folders and files collection to do the same in (4).

The best way would be to use any of the API methods as they are much faster.
 
Status
Not open for further replies.
Top Bottom