基本上,我希望命令行如下所示:
filename1.txt
This is filename1.txt's contents
if possible add in another string here
filename2.txt
This is filename2.txt's contents
等等
我当前的代码将此记录到控制台:
This is filename1.txt's contents
This is filename2.txt's contents
This is filename3.txt's contents
等等
我当前的代码:
string objPath = "plugins/Stats/" + p.truename + "/objectives/";
if (!Directory.Exists(objPath)) {
Console.Writeline("You have no objectives.");
}
else {
int fCount = Directory.GetFiles(objPath, "*", SearchOption.AllDirectories).Length;
if (fCount == 0) {
Console.Writeline("You have no objectives.");
}
else {
foreach (string file in Directory.EnumerateFiles(objPath, "*.txt")) {
string contents = File.ReadAllText(file);
Console.Writeline(contents);
}
}
}
只需使用:
Console.Writeline(file.Substring(file.LastIndexOf('\\') + 1));
之前 Console.Writeline(contents);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句