CH376FileOpen();和CH376FileOpenPath();
是不是只能打開實(shí)際的文件,而對(duì)文件夾無效?
更改文件夾而非文件的修改時(shí)間應(yīng)如何操作?
UINT8SetDirReviseTime( PUINT8 iFileName, UINT16 iReviseDate, UINT16 iReviseTime )
{
/* Time = (Hour<<11) + (Minute<<5) + (Second>>1) */
/* Date = ((Year-1980)<<9) + (Month<<5) + Day */
//修改文件夾修改時(shí)間
//2020.9.24?
UINT8s;
u8 buf[64];
strcpy(buf,iFileName);
s = CH376FileOpen( buf );? /* 打開文件 */
//s = CH376FileOpenPath( iFileName );
if ( s == USB_INT_SUCCESS ) {
/* 文件讀寫操作等... */
s = CH376DirInfoRead( );? /* 讀取當(dāng)前文件的目錄信息FAT_DIR_INFO,將相關(guān)數(shù)據(jù)調(diào)到內(nèi)存中 */
if ( s == USB_INT_SUCCESS ) {
buf[0] = (UINT8)iReviseTime;? /* 文件創(chuàng)建的時(shí)間,低8位在前 */
buf[1] = (UINT8)(iReviseTime>>8);? /* 文件創(chuàng)建的時(shí)間,高8位在后 */
CH376WriteOfsBlock( buf, STRUCT_OFFSET( FAT_DIR_INFO, DIR_WrtTime ), 2 );
buf[0] = (UINT8)iReviseDate;? /* 文件創(chuàng)建的日期,低8位在前 */
buf[1] = (UINT8)(iReviseDate>>8);? /* 文件創(chuàng)建的日期,高8位在后 */
CH376WriteOfsBlock( buf, STRUCT_OFFSET( FAT_DIR_INFO, DIR_WrtDate ), 2 );
s = CH376DirInfoSave( );? /* 保存文件的目錄信息 */
if ( s == USB_INT_SUCCESS ) {? /* 成功修改并保存 */
/* 文件讀寫操作等... */
}
}
CH376FileClose( FALSE );? /* 關(guān)閉文件 */
}
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);/* 創(chuàng)建多級(jí)目錄*/
s = CH376DirCreatePath(buf);?
mStopIfError(s);
//s = CH376FileCreate( FileName );/* 根目錄下創(chuàng)建短文件名文件*/
//mStopIfError(s);
sprintf(buf,"/TL2405%s%s",PathName,FileName);/* 多級(jí)目錄下創(chuàng)建短文件名文件*/
s = CH376FileCreatePath(buf);
mStopIfError(s);
//s = CreateEnglishLongFileName(FileName);//根目錄下創(chuàng)建英文長(zhǎng)文件名文件 有問題 刪除不用
//mStopIfError(s);
s = CH376ByteWrite(DataBuf, strlen(DataBuf), NULL );? /* 以字節(jié)為單位向當(dāng)前位置寫入數(shù)據(jù)塊 */
mStopIfError( s );
s=CH376FileClose(1);//關(guān)閉文件更新文件長(zhǎng)度
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);//~~~~~~~返回錯(cuò)誤代碼0x42
//s = SetDirReviseTime( "/TL2405",ConvertFileDate(year,month,day),ConvertFileTime(hour,minute,second));
//mStopIfError(s);
}
delay_ms( 200 );
return 0;
}