[英]How do I check if folder and sub folder exist in Outlook using EWS Web Service & C#
[英]How can i create "recursively" folder and sub folder in C#
**1875 科韋茲
1875 年科森巴尼亞
1875年萊倫茨
1875 年拉克塔尼亞克
第 1875 章
第 1876 章
1876 年希達克
**
我在txt文件中有這個文件結構
“說明:該行的第一部分是 4 位數字-它可以相等(和根文件夾名稱)並且它必須只包含相同的 4 位數字子文件夾。txt 文件很長,大約 18000 行
例子:
C:/DATA/1875/Kovezes C:/DATA/1875/Koszenbanya
private void button3_Click(對象發送者,EventArgs e)
{
string line;
string linecopy;
int linecopyc;
//string root = @"C:\Temp";
// string subdir = @"~/ASD/";
var file = new System.IO.StreamReader("adatforras.txt");
while ((line = file.ReadLine()) != null)
{
listBox1.Items.Add(line);
//linecopy = line;
linecopy = line.Substring(0,4);
label4.Text = linecopy;
linecopyc = line.Length - 4;
label4.Text = line.Substring(4, linecopyc);
if (!Directory.Exists(linecopy))
{
di = Directory.CreateDirectory(linecopy);
DirectoryInfo dis = di.CreateSubdirectory(label4.Text);
}
else
{
DirectoryInfo dis = di.CreateSubdirectory(label4.Text);
}
}
}
問題是:這段代碼的主要問題是什么?
我認為您的子字符串以空格開頭:
label4.Text = line.Substring(4, linecopyc);
嘗試修剪它或從位置 5 開始
label4.Text = line.Substring(5, linecopyc);
C# 支持能夠在通往所需路徑的路上創建路徑中的所有目錄,因此您可以執行以下操作:
while ((line = file.ReadLine()) != null) {
// Other parts with labels etc.
var directoryParts = line.split(" "); // To get number and name separately
System.IO.Directory.CreateDirectory(Path.Combine("C:\\Data", directoryParts[0], directoryParts[1]));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.