CH376FileOpen();和CH376FileOpenPath();
是不是只能打开实际的文件,而对文件夹无效?
更改文件夹而非文件的修改时间应如何操作?
UINT8SetDirReviseTime( PUINT8 iFileName, UINT16 iReviseDate, UINT16 iReviseTime )
{
/* Time = (Hour<<11) + (Minute<<5) + (Second>>1) */
/* Date = ((Year-1980)<<9) + (Month<<5) + Day */
//修改文件夹修改时间
//2020.9.24
UINT8s;
u8 buf[64];
strcpy(buf,iFileName);
s = CH376FileOpen( buf ); /* 打开文件 */
//s = CH376FileOpenPath( iFileName );
if ( s == USB_INT_SUCCESS ) {
/* 文件读写操作等... */
s = CH376DirInfoRead( ); /* 读取当前文件的目录信息FAT_DIR_INFO,将相关数据调到内存中 */
if ( s == USB_INT_SUCCESS ) {
buf[0] = (UINT8)iReviseTime; /* 文件创建的时间,低8位在前 */
buf[1] = (UINT8)(iReviseTime>>8); /* 文件创建的时间,高8位在后 */
CH376WriteOfsBlock( buf, STRUCT_OFFSET( FAT_DIR_INFO, DIR_WrtTime ), 2 );
buf[0] = (UINT8)iReviseDate; /* 文件创建的日期,低8位在前 */
buf[1] = (UINT8)(iReviseDate>>8); /* 文件创建的日期,高8位在后 */
CH376WriteOfsBlock( buf, STRUCT_OFFSET( FAT_DIR_INFO, DIR_WrtDate ), 2 );
s = CH376DirInfoSave( ); /* 保存文件的目录信息 */
if ( s == USB_INT_SUCCESS ) { /* 成功修改并保存 */
/* 文件读写操作等... */
}
}
CH376FileClose( FALSE ); /* 关闭文件 */
}
return( s );
}
//u8 mUDiskFileCreate(PUINT8 PathName,PUINT8 FileName,u8 *DataBuf)
u8 mUDiskFileCreate(u8 *DataBuf)
{
//PathName "YEAR2020"
//FileName short "ASDFGHJK.DOC"
//保存文件路径/Tl2405/YYMMDD/HHMMSS.DOC
//u8 buf[64]="test file abc 123456789\r98765431210\r\n";
u8 s=0;
u8 buf[64];
u8 *PathName;
u8 *FileName;
u16 year=0;
u8 month=0,day=0,hour=0,minute=0,second=0;
SD3077_ReadRTC();
year=((RTCDat.year)&0x0f)+10*((RTCDat.year)>>4)+2000;
month=((RTCDat.month)&0x0f)+10*((RTCDat.month)>>4);
day=((RTCDat.day)&0x0f)+10*((RTCDat.day>>4));
hour=((RTCDat.hour)&0x0f)+10*((RTCDat.hour>>4));
minute=((RTCDat.minute)&0x0f)+10*((RTCDat.minute>>4));
second=((RTCDat.second)&0x0f)+10*((RTCDat.second>>4));
sprintf(PathName,"/%d%2d%2d",year,month,day);
sprintf(FileName,"/%d%2d%2d.DOC",hour,minute,second);
//s = SetDirReviseTime(PathName,ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
//mStopIfError(s);
//s = SetDirReviseTime( "/TL2405",ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
//mStopIfError(s);
s = CH376DirCreate( "/TL2405" );/* 新建或者打开目录,该目录建在根目录下 */
mStopIfError(s);
sprintf(buf,"/TL2405%s",PathName);/* 创建多级目录*/
s = CH376DirCreatePath(buf);
mStopIfError(s);
//s = CH376FileCreate( FileName );/* 根目录下创建短文件名文件*/
//mStopIfError(s);
sprintf(buf,"/TL2405%s%s",PathName,FileName);/* 多级目录下创建短文件名文件*/
s = CH376FileCreatePath(buf);
mStopIfError(s);
//s = CreateEnglishLongFileName(FileName);//根目录下创建英文长文件名文件 有问题 删除不用
//mStopIfError(s);
s = CH376ByteWrite(DataBuf, strlen(DataBuf), NULL ); /* 以字节为单位向当前位置写入数据块 */
mStopIfError( s );
s=CH376FileClose(1);//关闭文件更新文件长度
mStopIfError( s );
s = SetFileCreateTime(buf,ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
mStopIfError(s);
s = SetFileReviseTime(buf,ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
mStopIfError(s);
//~~~~~~~~到这里都没问题
while ( CH376DiskConnect( ) == USB_INT_SUCCESS )
{/* 检查U盘是否连接,等待U盘拔出 */
delay_ms( 100 );
s = SetDirReviseTime(PathName,ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
mStopIfError(s);//~~~~~~~返回错误代码0x42
//s = SetDirReviseTime( "/TL2405",ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
//mStopIfError(s);
}
delay_ms( 200 );
return 0;
}