是否有.NET应用程序的一个通配符扩展选项?通配符、应用程序、选项、NET

由网友(無邪仍在ゝ不見天真)分享简介:我已经使用了 setargv.obj连接的扩展通配符参数的,在过去​​的一些C和C ++应用程序,但我找不到任何类似提及的.NET应用程序。有一个标准的方式来自动有你的应用程序的命令行参数的通配符扩展?(即扩大的* .doc从args参数一个条目来所有比赛的通配符)。P.S。我砍死的东西连同Directory.GetF...

我已经使用了 setargv.obj连接的扩展通配符参数的,在过去​​的一些C和C ++应用程序,但我找不到任何类似提及的.NET应用程序。

有一个标准的方式来自动有你的应用程序的命令行参数的通配符扩展?(即扩大的* .doc从args参数一个条目来所有比赛的通配符)。

P.S。我砍死的东西连同Directory.GetFiles()我目前的小项目,但不包括通配符路径(还),这将是很好的做到这一点不定制code。

更新:这里是我的粗略砍,作说明。它需要分开的参数路径和名称的GetFiles,但是这是一般的想法。链接setargv.obj成C或C ++应用程序将基本上完成所有的通配符扩展,使用户只遍历argv数组。

 
静态无效的主要(字串[] args)
{
    的foreach(字符串argString在args)
    {
        //分割成路径和通配符
        INT lastBackslashPos = argString.LastIndexOf('')+ 1;
        PATH = argString.Substring(0,lastBackslashPos);
        filenameOnly = argString.Substring(lastBackslashPos,
                                   argString.Length  -  lastBackslashPos);

        的String []的fileList = System.IO.Directory.GetFiles(路径,filenameOnly);
        的foreach(字符串文件名中的fileList)
        {
            //做的事情为每个文件
        }
    }
}
 

解决方案

您code样子究竟如何你应该这样做。

应用程序开发功能里的选项怎么没有ASP.NET

I've used the setargv.obj linking for Expanding Wildcard Arguments in the past for a number of C and C++ apps, but I can't find any similar mention for .net applications.

Is there a standard way to have your app's command line parameters automatically wildcard expanded? (i.e. expand *.doc from one entry in args parameter to all that match that wildcard).

P.S. I've hacked something together with Directory.GetFiles() for my current little project, but it does not cover wildcards with paths (yet), and it would be nice to do it without custom code.

Update: here is my rough hack, for illustration. It needs to split the parameters for path and name for the GetFiles, but this is the general idea. Linking setargv.obj into a C or C++ app would basically do all the wildcard expansion, leaving the user to only iterate over the argv array.


static void Main(string[] args)
{
    foreach (String argString in args)
    {
        // Split into path and wildcard
        int lastBackslashPos = argString.LastIndexOf('') + 1;
        path = argString.Substring(0, lastBackslashPos);
        filenameOnly = argString.Substring(lastBackslashPos, 
                                   argString.Length - lastBackslashPos);

        String[] fileList = System.IO.Directory.GetFiles(path, filenameOnly);
        foreach (String fileName in fileList)
        {
            //do things for each file
        }
    }
}

解决方案

Your code looks like exactly how you're supposed to do it.

阅读全文

相关推荐

最新文章