小编MTe*_*eck的帖子

读取命令行开关

我正在尝试在C#应用程序中读取用户参数.我知道如何根据位置阅读它们

string[] args = Environment.GetCommandLineArgs();
Run Code Online (Sandbox Code Playgroud)

但是我想从开关中读取它们

app.exe /f /d:foo
Run Code Online (Sandbox Code Playgroud)

我真的很难找到关于这样做的任何信息......

.net c#

17
推荐指数
2
解决办法
3万
查看次数

使用VBScript检查是否存在注册表项

我认为这很容易,但显然没有人这样做......我正在试图查看是否存在注册表项.我不在乎其中是否有任何值,如(默认).

这就是我一直在尝试的.

Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
objRegistry.GetStringValue &H80000003,".DEFAULT\Network","",regValue

If IsEmpty(regValue) Then
    Wscript.Echo "The registry key does not exist."
Else
    Wscript.Echo "The registry key exists."
End If
Run Code Online (Sandbox Code Playgroud)

我只想知道HKEY_USERES\.DEFAULT\.Network是否存在.我在搜索时发现的任何东西似乎都在讨论操纵它们,并且几乎认为密钥确实存在,因为如果它没有,它就会神奇地创建.

windows registry vbscript

12
推荐指数
3
解决办法
10万
查看次数

使用变量代替函数名称

我现在正在使用以下内容:

foreach (string file in files) {
    switch (filetype.Value) {
        case "ReadFile":
            ReadFile(file);
            break;
        case "ReadMSOfficeWordFile":
            ReadMSOfficeWordFile(file);
            break;
        case "ReadMSOfficeExcelFile":
            ReadMSOfficeExcelFile(file);
            break;
        case "ReadPDFFile":
            ReadPDFFile(file);
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

它有效,但感觉有点不对劲.Python的方式更像是这样的:

foreach string file in files:
    filetype.Value(file)
Run Code Online (Sandbox Code Playgroud)

我很难想象C#不能做这样的事情.可能是我的Google技能不好,但我似乎无法弄明白.

public static readonly IDictionary<string, Action<string>> FileTypesDict = new Dictionary<string,Action<string>> {
    {"*.txt", ReadFile},
    {"*.doc", ReadMSOfficeWordFile},
    {"*.docx", ReadMSOfficeWordFile},
    {"*.xls", ReadMSOfficeExcelFile},
    {"*.xlsx", ReadMSOfficeExcelFile},
    {"*.pdf", ReadPDFFile},
};
Run Code Online (Sandbox Code Playgroud)

 

foreach (KeyValuePair<string, Action<string>> filetype in FileTypesDict) {
    string[] files = Directory.GetFiles(FilePath, filetype.Key, SearchOption.AllDirectories);
    //System.Reflection.MethodInfo ReadFileMethod = ReadFile.GetType().GetMethod(filetype.Value);
    foreach (string …
Run Code Online (Sandbox Code Playgroud)

.net c#

7
推荐指数
2
解决办法
5413
查看次数

从目录结构构建字典

我正在尝试构建一个如下所示的字典:

nodes = {
    'var': {
        'type': 'd',
        'full_path': '/var'
        'active': True
        'www': {
            'type': 'd',
            'full_path': '/var/www',
            'active': True
            'index.html': {
                'type': 'f',
                'full_path': '/var/www/index.html',
                'active': False
            }
        'log': {
            'type': 'd',
            'full_path': '/var/log',
            'active': False
        }
    }
    'srv': {
        'type': 'd',
        'full_path': '/srv',
        'active': True
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要它由两部分构建......第一个需要来自所有内容都处于“活动”状态的文件系统。第二个需要来自所有内容均处于非活动状态的文件的完整路径列表。

所以...

nodes = {}
for f, d, r in os.walk(root_path):
    # append active items to nodes
for f in os.system(command_that_gets_files)
    # append inactive items to nodes; not overwriting active
Run Code Online (Sandbox Code Playgroud)

我确信我错过了细节......

python tree

1
推荐指数
1
解决办法
2961
查看次数

在python中处理html片段中的数据片段

我确定之前已经问过,但我无法在任何地方找到答案......

我有一个字符串,它基本上是HTML页面的一部分.看起来很像这样:

body = u'<div class="admonition warning">\n<p class="first admonition-title">Warning</p>\n<p class="last">Read all of this! ALL OF IT!</p>\n</div>\n<div class="section" id="pitfalls-and-common-mistakes">\n<h1>Pitfalls and Common Mistakes<a class="headerlink" href="#pitfalls-and-common-mistakes" title="Permalink to this headline">\xb6</a></h1>\n<p>New and old users alike can run into a pitfall. Below we outline issues that we\nsee frequently as well as explain how to resolve those issues. In the #nginx IRC\nchannel on Freenode, we see these issues frequently.</p>\n<div class="section" id="this-guide-says">\n<h2>This Guide Says<a class="headerlink" href="#this-guide-says" title="Permalink to this headline">\xb6</a></h2>\n<p>The most frequent issue we see happens when …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
228
查看次数

标签 统计

.net ×2

c# ×2

python ×2

registry ×1

tree ×1

vbscript ×1

windows ×1