www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - wildcard expansion for D args

reply Jay Norwood <jayn prismnet.com> writes:
Below is a code fragment I'm using to expand pathname argv args in some
directory processing code.  Works pretty well.   Basically, I'm allowing
expansion of just the basename; so strings like these below are expanded into
expDir[] for each matching path  in the dirname directory, which is determined
by the shallow spanmode.  The last arg to dirEntries determines whether it
follows links.  In this case I'm not following them.

c:\dir1\xx* 
c:\dir2\x?d

There is a special dirEntries call that appears to be intended exactly for
this.  You need to include std.file and std.path


		string[] expDirs; // expanded directories from wildargv expansion on arg
		string basename = baseName(arg);
		string dirname = dirName(arg);

		// expand the wildargs for the single level.  Don't follow links
		auto dFiles = dirEntries(dirname,basename,SpanMode.shallow,false);
		foreach(d; dFiles){
			expDirs ~=  d.name;
		}
Feb 14 2012
parent Jay Norwood <jayn prismnet.com> writes:
So, there are some wildargv C  implementations around that can substitue for
the argv initializations, which would provide argv expansion before it got to
main.  Are there any options for argv expansion in the D libraries.   I suppose
in linux this is all supplied by the shell, but in Windows it would help to
have optional argv expansion.
Feb 14 2012