Wrox Programmer Forums
|
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2006, 11:53 AM
Authorized User
 
Join Date: Dec 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default File System Object equivalent?

What's the best thing to use in VB 2005 to replace the file system object I used in VB6?

 I can't seem to get any reference to System.IO.Filesystem working ("Visual Basic 2005" page 983) and my.computer.filesystem doesn't seem to define the file object for example.

 
Old December 13th, 2006, 10:53 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry about that. Page 983 is misleading. FileSystem doesn't seem to be in System.IO, it's My.Computer.FileSystem. In real life, it's defined in the Microsoft.VisualBasic.FileIO namespace. I need to fix that appendix.

The System.IO.File class provides Shared methods for working with files: AppendText, Create, Copy, Exists, Delete, etc. See page 986.

My guess is that you want the FileInfo class (page 991). A FileInfo object represents a file and has methods for working with it. For example, you create the object like this:

    Dim file_info As New FileInfo("C:\test.txt")

Then you can use its methods:

    If file_info.Exists() Then ...

If that's not what you mean, let me know what you want to do with the file and I'll see if I can find the appropriate class.


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old December 13th, 2006, 01:09 PM
Authorized User
 
Join Date: Dec 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rod...

I'm missing something basic :] here! I'm struggling with my first VB6-to-.net project and I cant find any way to reference FileInfo.

If I type (as you suggest),
  Dim file_info As New FileInfo("C:\test.txt")
I get an error - Type 'FileInfo' is not defined.

I'm obviously missing something about namespaces or framework classes. What do I need to do?

 
Old December 14th, 2006, 10:51 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

You need to tell VB what namespace to look in for the class. You can either provide the full namespace in the object like this:

    Dim file_info As New System.IO.FileInfo("C:\test.txt")

Or you can use an Imports statement. At the *very* top of the file before anything else, put:

    Imports System.IO

That tells VB to look in the System.IO namespace for objects. Now you can use this:

    Dim file_info As New FileInfo("C:\test.txt")


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html





Similar Threads
Thread Thread Starter Forum Replies Last Post
File System Object question fogofogo Classic ASP Basics 1 December 8th, 2005 04:14 PM
File System Object kumar_rajeshk Pro VB 6 7 April 28th, 2004 01:35 AM
File System Object Permissions kilika Classic ASP Basics 2 August 6th, 2003 09:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.