MoI discussion forum
MoI discussion forum

Full Version: Get list of subfolders

From: vector illustrator (QUARITEXA)
8 Jan 2020   [#1]
I need to get list of 'commands' subfolders.
I tried this:
code:
new ActiveXObject("Scripting.FileSystemObject").GetFolder(moi.filesystem.getCommandsDir()).SubFolders.count;

It returns right amount of subfolders. But I don't know how to get the list.
From: Michael Gibson
8 Jan 2020   [#2] In reply to [#1]
Hi Quaritexa, there is a moi.filesystem.getFiles() for getting a list of all files in a folder, but nothing currently for getting all directories. I will see about adding that in for the next v4 beta.

ActiveXObject is not supported on v4 anymore. There is an example here on how to iterate through the FileSystemObject Folders collection (which SubFolders returns) here: https://support.microsoft.com/en-us/help/229693/how-to-use-jscript-or-javascript-to-traverse-through-a-collection . I'm not sure if that uses something special from Microsoft's JScript script engine though. It may not work in MoI since starting with MoI v3 it uses the WebKit JavaScriptCore script engine instead of the Microsoft JScript script engine.

- Michael
From: Michael Gibson
8 Jan 2020   [#3] In reply to [#1]
Hi Quaritexa, I've added a moi.filesystem.getDirs() method for the next v4 beta that will do this.

For v3 a method that you could try is doing something like a moi.filesystem.shellExecute( 'cmd.exe', '/C /Q dir c:\\ > c:\\scripts\\filename.txt' ) , that should run the dir command of the shell and output it to a file. Then you would need to parse the file.

- Michael
From: vector illustrator (QUARITEXA)
8 Jan 2020   [#4] In reply to [#3]
I tried
code:
var cd = moi.filesystem.getCommandsDir(); 
moi.filesystem.shellExecute('cmd.exe', '/c dir /a:d /b /o:n "' + cd + '" > "' + cd + 'dir.tmp"');

But it displays the shell window. How to suppress it?
From: Phiro
8 Jan 2020   [#5] In reply to [#4]
In your command line the /q option is missing
Perhaps is it the problem
The /c option is use to close the Window but /q avoids the echo
From: Michael Gibson
8 Jan 2020   [#6] In reply to [#4]
Hi Quaritexa,

re:
> But it displays the shell window. How to suppress it?

A couple of possibilities here:
https://superuser.com/questions/191149/how-to-execute-cmd-exe-silently

Maybe this one:
http://www.joeware.net/freetools/tools/quiet/

- Michael
From: vector illustrator (QUARITEXA)
9 Jan 2020   [#7] In reply to [#6]
Thank you, Michael.

I chose this one:
code:
var pd = moi.filesystem.getProcessDir();
var cd = moi.filesystem.getCommandsDir(); 
moi.filesystem.shellExecute(pd + 'nircmd', 'exec hide cmd.exe /c dir /a:d /b /o:n '+ cd + '> '+ cd + 'dir.tmp');