【问题标题】:Split a Folder Path and File Name [duplicate]拆分文件夹路径和文件名[重复]
【发布时间】:2014-12-16 06:50:46
【问题描述】:

我有一个要拆分的文件夹路径和文件名。两条路径是:F:\AutoImport - Folder\20141612\Inv.trgF:\EmailImport\rohan@yahoo.com_01-01-2014_05-05-22\Inv.trg

所以我想分割这条路径,而且我只想要路径中的“Rohan”名称和“20141612”。请建议我如何使用 C# 编码在 .net 中实现这一点。

此名称需要用作 Kofax Capture 批次名称中的自定义名称。截至目前,批次名称为:45- F:\EmailImport\ram@afcl.com_09-01-2014_10-02-30\New Text Document.trg。我也不知道 45- 从哪里来,这个批次名称来自 Kofax 提供的示例脚本。

【问题讨论】:

  • 将 C# 拆分字符串输入谷歌
  • 这样的答案很多stackoverflow.com/questions/4323874/…提问前请先搜索
  • @JRLambert - 请不要。使用来自System.IO.Path 的适当方法。
  • 查看答案。这是你需要的吗?
  • @Corak mypath.Split(Path.DirectorySeparatorChar)) 返回数组,然后 myPathArray.Lenth - 2 作为所需文件夹的索引。

标签: c# file ocr kofax


【解决方案1】:

这是您的输出。通过使用String.Split(),您可以轻松实现:

string filepath1 = @"F:\EmailImport\rohan@yahoo.com_01-01-2014_05-05-22\Inv.trg";
System.IO.FileInfo fif = new System.IO.FileInfo(filepath1);
string folderdet = fif.Directory.Name;
string[] arr1 = folderdet.Split('@');
string myname = arr1[0];
Console.WriteLine(myname);

string filepath2 = @" F:\AutoImport - Folder\20141612\Inv.trg";
System.IO.FileInfo fileinfo = new System.IO.FileInfo(filepath2);
string foldername = fileinfo.Directory.Name;
Console.WriteLine(foldername);

检查一下,如果您有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 2015-02-15
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    相关资源
    最近更新 更多