c35; 的“dir”(也称为“获取字符”) powershell cmdlet。
不是你是否应该。 )
必须将此引用添加到项目文件中(
. csproj "或"
. vcproj“”手动:
这里有作业步骤:
使用系统;
using system.collections.generic;
using system.management.automation;
using system.management.automation.run spaces;
using system.collections.object model;
namespace CsWildcard {
类程序{
staticienumerablecmdletdirglobbing (string basepath,string glob ) {
runspace.Open (;
//cd to basePath
基本路径!=null ) {
pipelinecdpipeline=run space.create pipeline (;
commandCDcommand=newcommand(CD );
CDcommand.parameters.add('path ',basePath );
CD pipeline.commands.add (CD command;
cdPipeline.Invoke (; //run the cmdlet
}
//runthe ' dir ' cmdlet (e.g.' dirc : (* (*.txt ) ) )
pipelinedirpipeline=run space.create pipeline (;
commanddircommand=new command (dir );
dir command.parameters.add (' path ',glob );
dir pipeline.commands.add (dir command;
collectiondiroutput=dir pipeline.invoke (;
//for each found file
foreach { psobjectpsobjectindiroutput }
//lookforthefullpath('fullname ) )。
foreach (pspropertyinfopspropertyinfoinpsobject.properties ) {
pspropertyinfo.name==' full name ' ) }
yeldreturnpspropertyinfo.value.tostring (; //yield it
}
}
}
}
staticvoidmain (字符串野性之缘args ) )。
foreach (stringpathincmdletdirglobbing (null,' c: ) ((((() () (*.txt ) ) ) ) }
system.console.writeline(path );
}
foreach (stringpathincmdletdirglobbing (c : (,)、((((((() ).exe ) ) )
system.console.writeline(path );
}
Console.ReadKey (;
}
}
}