Solved

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

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now