Solved

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

Posted on 2008-06-23
4
3,447 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
  • 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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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