【问题标题】:Date of creation of a folder in windows in c在c中的Windows中创建文件夹的日期
【发布时间】:2018-08-18 12:56:24
【问题描述】:

我需要目录中所有文件的创建日期,它适用于所有文件,但不适用于文件夹。

int antiguedad(char * nombre){

ZeroMemory(&fileinfo, sizeof(BY_HANDLE_FILE_INFORMATION));
// obtain a handle to the file, in this case the file
// must be in the same directory as your application
HANDLE myfile = NULL;
//char * nombre = "nuevooo.txt";
myfile = CreateFileA(nombre,0x00,0x00,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

// if we managed to obtain the desired handle
if(myfile!=INVALID_HANDLE_VALUE)
{
    //try to fill the structure with info regarding the file
    if(GetFileInformationByHandle(myfile, &fileinfo))
    {
       SYSTEMTIME systemTime;
       FileTimeToSystemTime(&fileinfo.ftCreationTime, &systemTime);
       printf("El archivo tiene %i dias \n", diferenciaEndias(systemTime.wDay,systemTime.wMonth, systemTime.wYear));
    }
    CloseHandle(myfile);
}
else {

    printf("IT A FOLDER \n");
}
return 0;

}

我认为文件夹需要特定代码,但我什么也没找到

【问题讨论】:

    标签: c windows time directory creation


    【解决方案1】:

    避免使用 FILE_ATTRIBUTE_NORMAL(它实际上意味着所有其他属性不存在,包括只读/存档/系统/隐藏等,因此它可能与您的期望不符 - 尽管它可以是根据 CreateFile 意图忽略)。

    要获取文件夹的有效句柄,请包含 FILE_FLAG_BACKUP_SEMANTICS。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多