Solved

Convert VB to C#, Scripting.FileSystemObject becomes what..?

Posted on 2008-06-23
4
3,477 Views
Last Modified: 2013-12-16
I have a very simple VB.NET (I assume it's .NET, may be old style VB) application that I am trying to convert to C#

Here is the problem code:

Dim fso As New Scripting.FileSystemObject
Dim fdr As Folder
Dim fil As File

fdr = fso.GetFolder(path)

For Each fil In fdr.Files
   do stuff
Next

I'm assuming the Folder is translated to an object of type System.IO.Directory, and File is System.IO.File, but I couldn't find an equivalent for the FileSystemObject.

What would the other functionality translate to?
0
Comment
Question by:FrancineTaylor
[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
  • 2
4 Comments
 
LVL 11

Expert Comment

by:CMYScott
ID: 21851558
you're kinda talking apples and oranges here..

your VB.NET code is using Windows Scripting objects - which obviously will work.  

what you're talking about is not only converting it to C# - but also eliminated the Windows Script objects to .NET Framework classes/objects.

In any case - the classes you want are all in System.IO namespace.  Pay particular attention to:

File
FileInfo
Directory
DirectoryInfo

Directory and DirectoryInfo both have methods for GetFiles


0
 
LVL 11

Expert Comment

by:CMYScott
ID: 21851566
sorry - eliminated should be 'converted' in the 3rd line
0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 500 total points
ID: 21851570
All your questions are answered here: http://support.microsoft.com/default.aspx/kb/304430

Attached is a code snippet that is the equivalent of yours in C# - and is copied directly from the link above, so read through the link and you should be able to see what is needed.
    string[] files= Directory.GetFiles(winDir);
    foreach (string i in files)
    {
        addListItem(i);
    }

Open in new window

0
 
LVL 1

Author Closing Comment

by:FrancineTaylor
ID: 31470014
Thanks, that's just what I needed...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 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