我目前有这个代码,它返回文件总数,但我不想计算这个数字计数中的多个文件?
让我说我有这个:
01Red.txt
01Blue.txt
02Red.txt
05Red.txt
05Green.txt
Get-ChildItem -File *.txt -Path "C:\Users\Test\Desktop\TestDirectory" | Measure-Object | %{$_.Count}
Run Code Online (Sandbox Code Playgroud)
我想基于01,02,05返回总计数3但是我的代码我得到5.
如何让它返回3并忽略字符串中前2个字符后的所有内容?
我将 dll 安装到了 GAC 中,甚至更新了 dll 以将其安装到了 GAC 中,但出现以下错误:
“无法加载文件或程序集“Newtonsoft.Json,版本=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。系统找不到指定的文件。”:“Newtonsoft.Json,版本=4.5 .0.0,文化=中立,PublicKeyToken=30ad4fe6b2a6aeed”}
应用程序配置
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
广汽集团地点:
C:\ Windows \ Microsoft.NET \ assembly \ GAC_MSIL \ Newtonsoft.Json \ v4.0_12.0.0.0__30ad4fe6b2a6aeed \ Newtonsoft.Json.dll
我还将 dll 复制到了 C:\Windows\System32,但是当我尝试从该位置将其添加为引用时,视觉工作室看不到它。
我正在使用 SSH.NET 上传。但如果进程失败,我想重试 sftp 文件。我有这段代码,但我认为这不是处理重试的最佳方法。处理这个问题的最佳方法是什么?
var exceptions = new List<Exception>();
int retryCount = 3;
for (int retry = 0; retry < retryCount; retry++)
{
try
{
var filePath = Path.Combine(path, fileName);
var client = new SftpClient("ftp.site.com", 22, "userName", "password");
client.Connect();
if (client.IsConnected)
{
var fileStream = new FileStream(filePath, FileMode.Open);
if (fileStream != null)
{
client.UploadFile(fileStream, "/fileshare/" + fileName, null);
client.Disconnect();
client.Dispose();
}
}
}
catch (Exception ex)
{
exceptions.Add(ex);
System.Threading.Thread.Sleep(10000);
}
if (exceptions.Count == 3)
{
throw exceptions[0];
}
}
Run Code Online (Sandbox Code Playgroud)