Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-23
4
Medium Priority
?
3,553 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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