deleyd
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>
}
Not being familiar with AutoHotKeys myself, maybe you could explain what the code is doing?
objShell = new ComObjCreate("Shell.Applic ation");
objFolder = objShell.Namespace("Target Folder");
for (int i=0;i<30;i++)
{
Tstr = objFolder.GetDetailsOf(obj Folder.Ite ms, i);
Console.WriteLine("You Output : " + Tstr);
}
objFolder = objShell.Namespace("Target
for (int i=0;i<30;i++)
{
Tstr = objFolder.GetDetailsOf(obj
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);
}
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\shell 32.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.
I can get this info from Shell32 (C:\Windows\System32\shell
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.)