?
Solved

Translate 6 lines of code to C#?

Posted on 2011-02-23
8
Medium Priority
?
1,088 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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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…

764 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