public static void TIF(Document dc, SortedList<string, object> dcIndexes)
{
string str1 = dcIndexes["Document,name"].ToString();
string str2 = dcIndexes["Document,age"].ToString();
string str5 = dcIndexes["Document,status"].ToString();
string str3 = Path.Combine(Config.OutputFolder, DateTime.Now.ToString("yyyyMMdd"));
if (!Directory.Exists(str3))
Directory.CreateDirectory(str3);
string str4 = Path.Combine(str3, str1 + "_" + str2 + "_" + str5 + ".tif");
DocumentHistory dh = (DocumentHistory) null;
string sourceFileName = ServiceES.FromSE(dc, out dh);
if (File.Exists(str4))
File.Delete(str4);
File.Move(sourceFileName, str4);
PTrace.LogInformation("{0} - TIF - {1}", (object) dc.Title, (object) str4);
}
输出路径现在为\YYYYMMDD\NAME_AGE_STATUS.tif
如果“name”为空,则图片名称将变为:\YYYYMMDD\_AGE_STATUS.tif
我现在的问题是,数据库中有相同的年龄和状态。图像只会替换为第二张和第三张图像后面的第一张图像,最后只有一张图像。
我可以知道如何添加一个正在运行的号码?
示例:\YYYYMMDD\_AGE_STATUS.tif (first image)
,\YYYYMMDD\_AGE_STATUS_001.tif (second image)
跟随\YYYYMMDD\_AGE_STATUS_002.tif (third image).
if can remove the "_" front of AGE will look better.
example:
\ YYYYMMDD \ AGE_STATUS_002.tif`
它似乎因为下面的代码不允许:
if (File.Exists(str4))
File.Delete(str4);
如果重复的tif,如何添加序列号001,002,003? 现在重复了10个文件名。
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
_23_Single
成为:
_23_Single
_23_Single_001
_23_Single_002
_23_Single_003
_23_Single_004
_23_Single_005
_23_Single_006
_23_Single_007
_23_Single_008
_23_Single_009
或成为:
23_Single
23_Single_001
23_Single_002
23_Single_003
23_Single_004
23_Single_005
23_Single_006
23_Single_007
23_Single_008
23_Single_009
答案 0 :(得分:2)
您必须创建文件名,检查它,然后在文件存在时更改它。例如:
public static void TIF(Document dc, SortedList<string, object> dcIndexes)
{
string str1 = dcIndexes["Document,name"].ToString();
string str2 = dcIndexes["Document,age"].ToString();
string str5 = dcIndexes["Document,status"].ToString();
string str3 = Path.Combine(Config.OutputFolder, DateTime.Now.ToString("yyyyMMdd"));
if (!Directory.Exists(str3))
Directory.CreateDirectory(str3);
// ********
// find first available file name
bool done = false;
int sequence = 0;
string str4;
string baseName = str1 + "_" + str2 + "_" + str5;
do
{
// change here ***
string fname = baseName;
if (sequence > 0)
fname = fname + "_" + sequence.ToString();
// end of change ***
str4 = Path.Combine(str3, fname + ".tif");
if (File.Exists(str4))
++sequence;
else
done = true;
} while (!done);
// str4 now contains the file name
// ********
DocumentHistory dh = (DocumentHistory) null;
string sourceFileName = ServiceES.FromSE(dc, out dh);
if (File.Exists(str4))
File.Delete(str4);
File.Move(sourceFileName, str4);
PTrace.LogInformation("{0} - TIF - {1}", (object) dc.Title, (object) str4);
}
答案 1 :(得分:0)
我只想数,已存在多少个文件
string fileName = // your file name
int filesWithThisName = 1;
while(File.Exists(fileName))
{
fileName = Path.Combine(str3, str1 + "_" + str2 + "_" + str5 + "_" + i.ToString("D3") + ".tif");
i++;
}
// save file