C#使用file无法修改netware操作系统下的文件创建日期
因某些原因需要更改Netware网络操作系统下的文件创建时间,但只能更改最近修改时间,文件创建时间修改不成功。
相同代码在更改Windows服务器的文件时可以更改成功。
代码如下:
public void RefreshFilterFilesDate(string strFilter, string strPath, int iYear, int iMonth, int iDay, int iHour, int iMinute)
{
int deYear, deMonth, deDay, deHour, deMinute;
bool isExist = System.IO.Directory.Exists(strPath);
if (isExist)
{
deYear = iYear;
deMinute = iMonth;
deDay = iDay;
deHour = iHour;
deMinute = iMinute;
string[] myTxtFiles = Directory.GetFiles(strPath, strFilter, SearchOption.AllDirectories);
foreach (string myTxtFile in myTxtFiles)
{
DateTime dateModified;
DateTime oldDate, newDate;
myNCFile = myTxtFile;
oldDate = File.GetCreationTime(myTxtFile);
dateModified =File.GetLastWriteTime(myTxtFile);
if (oldDate.CompareTo(dateModified) < 0)
{
oldDate = dateModified;
}
deYear = iYear == 0 ? 2002 : iYear;
deMonth = iMonth == 0 ? oldDate.Month : iMonth;
deDay = iDay == 0 ? oldDate.Day : iDay;\\问题出在这里,月份为2,日期〉28时出错
deHour = iHour == 0 ? oldDate.Hour : iHour;
deMinute = iMinute == 0 ? oldDate.Minute : iMinute;
newDate = new DateTime(deYear, deMonth, deDay, deHour, deMinute, oldDate.Second,oldDate.Millisecond);
TimeSpan ts = newDate.Subtract(oldDate);
if (newDate != oldDate)
{
File.SetCreationTime(myTxtFile, newDate);
File.SetLastWriteTime(myTxtFile, newDate);
myNCFile = myNCFile + "\t" + oldDate + "\t" + newDate;
InvokeDoWith mi = new InvokeDoWith(AddLVItem);
this.Invoke(mi);
}
}
}
}
您有什么方法实现吗?