Notifications
Clear all

[Closed] GetDirectories for root server won't work

I can get a list of directories for this path on LAN

GetDirectories (@"\\S003\all"+"/*")

but, I get empty array with

 GetDirectories (@"\\S003"+"/*")

Please, anyone, can help me get the list of all shared folders?

6 Replies

You probably want to look at dotNet instead…

I’ve tried already, no luck:

	fn collectFiles root: =
	(
		local sioDir = dotNetClass "System.IO.Directory"
		local sioSOpt = (dotNetClass "System.IO.SearchOption").AllDirectories
		local allFiles = sioDir.GetFiles root "*.*" sioSOpt
	)

collectFiles root:@”\S003\all” is working

collectFiles root:@”\S003″ throws an error:

– Runtime error: dotNet runtime exception: The UNC path should be of the form \server\share.

Hi, LO!
I saw that post, unfortunately I don’t know how to convert it to maxscript

there is a requirement – Appropriate permissions are required.

In fact, for me it’s enough the permission to read files.

It would probably be easier to make the function in C#, compile it to assebly/dll, then load the assembly in maxscript to use the function.

There’s also a way using wmic command:

fn getNetworkShareNames computer: user: pass: tmpFilename:"wmic_netShare_temp.txt" =
(
	local filePath = (symbolicPaths.getpathvalue "$temp") + tmpFilename
	local command = stringstream ""
	format "wmic %%% share get name > \"%\"" \
		(if computer != unsupplied then "/node:\"" + computer + "\" " else "") \
		(if user != unsupplied then "/user:\"" + user + "\" " else "") \
		(if pass != unsupplied then "/password:\"" + pass + "\"" else "") \
		filepath \
		to:command
	command = command as string

	local retVal = DOScommand command

	if retVal == 0 then
	(
		local shares = #()
		local item
		local F = openFile filepath
		-- Throw away column titles line:
		readLine F 
		while (NOT eof F) do
		(
			item = readLine F
			-- Ignore admin shares:
			if NOT (matchpattern item pattern:"*$*") then
			(
				append shares (trimRight item)
			)
		)
		close F
		RETURN shares
	)
	else 
	(
		print "Failed to get shares: WMI get shares exited with an error."
		RETURN undefined
	)
)

Correct me if I’m wrong, but either way, when dealing with WMI, several limitations will be present:

  1. it’s very likely that you will need to pass login credentials.
  2. Windows Management Instrumentation (WMI-in) rule will have to be enabled in the target machine’s firewall.
  3. you will be limited to windows machines; you will not be able to get shares of a linux server, which includes most NAS.