Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

Translate 6 lines of code to C#?

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

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Not being familiar with AutoHotKeys myself, maybe you could explain what the code is doing?
Avatar of DOTNET_GURU
DOTNET_GURU

 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);
  }

Yeah, I think it's going to take a little more than just changing it to look a little more like C# syntax!!
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

Avatar of deleyd

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deleyd

ASKER

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.)