Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
ENTHU
Level III

searching for a folder.

I have a code to accept folder name as input .Now I want to check if the folder exists in one of the 2 paths (pathA and PathB).

I was also able to achieve this but the challenge is,

I have many folders in these 2 paths and I dont know the name of these before-hand.

I tried using 

filelist=Files In Directory( path1, recursive);

but this doesnt work for folders. 

3 REPLIES 3
Highlighted
pauldeen
Level IV

Re: searching for a folder.

Will this help you?

If( Directory Exists( "$SAMPLE_DATA/Loss Function Templates" ),
	"ok",
	"missing!"
);
Highlighted

Re: searching for a folder.

Your code example uses the wrong syntax. Here is an example of the correct syntax:

 

Files In Directory( "$SAMPLE_DATA", Recursive( 1 ) );

The items in the list that is returned are full paths, so you can examine each one to find the target folders.

Learn it once, use it forever!
Highlighted
Craige_Hales
Staff (Retired)

Re: searching for a folder.

descend = Function( {path},
	{candidates, i},
	If( !Ends With( path, "/" ) & !Ends With( path, "\" ),
		path = path || "/"
	);
	candidates = Files In Directory( path ); // not recursive
	For( i = 1, i <= N Items( candidates ), i += 1,
		If( Is Directory( path || candidates[i] ),
			Write( "\!n", path || candidates[i] ); // <<<<<< do something
			descend( path || candidates[i] ); // optionally, recurse
		)
	);
);

descend( "c:\program files" );

If you don't want to explore sub directories, comment out the recursive line.

Craige
Article Labels

    There are no labels assigned to this post.