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.
Re: searching for a folder.Needed slight tweak, but thank you for that! Got what I needed
Re: searching for a folder.sure, approximately like this untested bit of JSL...
If( Is Directory( path || candidates[i] ),
Write( "\!n", path || candidates[i] ); // <<<<<< do something with a dir
descend( path || candidates[i] ); // optionally, recurse
, // else
Write( "\!n", path || candidates[i] ); // <<<<<< do something with a file
)
You might need to use isFile(...) to make sure items are actually files and not other odd things the OS might show you.
Re: searching for a folder.Can the code be amended to also include the file names as well as the folders?
thanks
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.
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.
Re: searching for a folder.Will this help you?
If( Directory Exists( "$SAMPLE_DATA/Loss Function Templates" ),
"ok",
"missing!"
);