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

x
?
Solved

Translate 6 lines of code to C#?

Posted on 2011-02-23
8
Medium Priority
?
1,091 Views
Last Modified: 2012-05-11
I'm good at programming AutoHotkey scripts. I'm learning C#. Could someone translate this snippet of code to C# for me?

  objShell := ComObjCreate("Shell.Application")
  objFolder := objShell.Namespace(TargetFolder . "\")

  i := 0
  loop, 30
  {
    Tstr := objFolder.GetDetailsOf(objFolder.Items, i)
    <write Tstr to console>
  }

Open in new window

0
Comment
Question by:deleyd
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34959742
Not being familiar with AutoHotKeys myself, maybe you could explain what the code is doing?
0
 
LVL 1

Expert Comment

by:DOTNET_GURU
ID: 34959824
 objShell = new ComObjCreate("Shell.Application");
  objFolder = objShell.Namespace("TargetFolder");

  for (int i=0;i<30;i++)
  {
    Tstr = objFolder.GetDetailsOf(objFolder.Items, i);
    Console.WriteLine("You Output : " + Tstr);
  }

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34959841
Yeah, I think it's going to take a little more than just changing it to look a little more like C# syntax!!
0
Technology Partners: 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!

 
LVL 8

Expert Comment

by:mac-will
ID: 34964422
You are printing the contents of a directory to the console?

[NOTE: using System.IO;]


            DirectoryInfo source = new DirectoryInfo(@"\");
            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {
                Console.WriteLine("Directory: " + diSourceSubDir.Name);
            }

            foreach (FileInfo fi in source.GetFiles())
            {
                Console.WriteLine("File: " + fi.Name);
            }

Open in new window

0
 

Author Comment

by:deleyd
ID: 34966299
OK I see I need to give a bit more of what I'm trying to do. In Windows File Explorer it lists various attributes for a file. Under VIEW -> CHOOSE DETAILS there's an extensive list of things I can list about a file, such as if it's a music file I can list the 'Album', 'Artists', 'Title', 'Comments', 'Year', etc.

I can get this info from Shell32 (C:\Windows\System32\shell32.dll). The AutoHotkey script above does this using a COM interface.

I bet there's a better way in C# since COM is sort of old and going obsolete from what I've been reading lately.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 34967799
Actually I think you'll still need to use Shell. So you'll need to add a reference to the "Microsoft Shell Controls And Automation" from the COM tab of the Add Reference dialog.

After that, you can try:
            Shell32.Shell shell = new Shell32.Shell();
            Shell32.Folder folder = shell.NameSpace(@"somefolder");

            for (int i = 0; i != 30; ++i)
            {
                string value = folder.GetDetailsOf(folder, i);
                Console.WriteLine(value);
            }

Open in new window

0
 
LVL 8

Assisted Solution

by:mac-will
mac-will earned 1000 total points
ID: 34969988
good find @carl_tawn!

Extending this a little:

            DirectoryInfo source = new DirectoryInfo(@"C:\Users\NAME\Music");

            Shell32.Shell shell = new Shell32.Shell();
            Shell32.Folder folder = shell.NameSpace(source.FullName);

            foreach (FileInfo fi in source.GetFiles())
            {
                Shell32.FolderItem fileItem = folder.ParseName(fi.Name);
                for (int i = 0; i != 50; ++i)
                {
                    string attrib = folder.GetDetailsOf(folder, i);
                    string value = folder.GetDetailsOf(fileItem, i);
                    Console.WriteLine(attrib + " : " + value);
                }
            }

Open in new window

0
 

Author Closing Comment

by:deleyd
ID: 34990416
Super! (thought I already said "Super!". Surprised to see question is still open. OK I'll say "Super!" again. See if it works this time.)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

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