?
Solved

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

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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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