当前位置: 首页>>代码示例>>C++>>正文


C++ SetFileTime函数代码示例

本文整理汇总了C++中SetFileTime函数的典型用法代码示例。如果您正苦于以下问题:C++ SetFileTime函数的具体用法?C++ SetFileTime怎么用?C++ SetFileTime使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetFileTime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: set_date_time

static char set_date_time(char *filename, unsigned long date, unsigned long time)
  {
#if 0
  HANDLE h=CreateFile(filename,0,0,NULL,OPEN_EXISTING,0,NULL);
  FILETIME WriteTime;
  char err=0;
  if (h==NULL) return 1;
  WriteTime.dwHighDateTime=date;
  WriteTime.dwLowDateTime=time;
  err=SetFileTime(h,NULL,NULL,&WriteTime)==1;
  CloseHandle(h);
  return err;
#endif
  return 0;
  }
开发者ID:svn2github,项目名称:Brany_Skeldalu,代码行数:15,代码来源:save_map.c

示例2: os_set_file_time

bool os_set_file_time(const std::string& fn, int64 created, int64 last_modified, int64 accessed)
{
	HANDLE hFile = CreateFileW(ConvertToWchar(fn).c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL,
		OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

	if(hFile!=INVALID_HANDLE_VALUE)
	{
		FILETIME* pcreation_time = NULL;
		FILETIME creation_time;
		if (created != 0)
		{
			LARGE_INTEGER li;
			li.QuadPart=os_to_windows_filetime(created);

			
			creation_time.dwHighDateTime=li.HighPart;
			creation_time.dwLowDateTime=li.LowPart;	

			pcreation_time = &creation_time;
		}
		
		LARGE_INTEGER li;
		li.QuadPart = os_to_windows_filetime(last_modified);
		FILETIME modified_time;
		modified_time.dwHighDateTime=li.HighPart;
		modified_time.dwLowDateTime=li.LowPart;

		li.QuadPart=os_to_windows_filetime(accessed);

		FILETIME accessed_time;
		accessed_time.dwHighDateTime = li.HighPart;
		accessed_time.dwLowDateTime = li.LowPart;

		if(SetFileTime(hFile, pcreation_time, &accessed_time, &modified_time))
		{
			CloseHandle(hFile);
			return true;
		}
		else
		{
			CloseHandle(hFile);
			return false;
		}
	}
	else
	{
		return false;
	}
}
开发者ID:uroni,项目名称:urbackup_backend,代码行数:49,代码来源:os_functions_win.cpp

示例3: Touch

void Touch(path const& file) {
    CreateDirectory(file.parent_path());

    SYSTEMTIME st;
    FILETIME ft;
    GetSystemTime(&st);
    if(!SystemTimeToFileTime(&st, &ft))
        throw EnvironmentError("SystemTimeToFileTime failed with error: " + util::ErrorString(GetLastError()));

    scoped_holder<HANDLE, BOOL (__stdcall *)(HANDLE)>
    h(CreateFile(file.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr), CloseHandle);
    // error handling etc.
    if (!SetFileTime(h, nullptr, nullptr, &ft))
        throw EnvironmentError("SetFileTime failed with error: " + util::ErrorString(GetLastError()));
}
开发者ID:rcombs,项目名称:Aegisub,代码行数:15,代码来源:fs.cpp

示例4: SetFileTime

Word Burger::File::SetCreationTime(const TimeDate_t *pInput)
{
	Word uResult = FILENOTFOUND;
	HANDLE fp = m_pFile;
	if (fp) {
		FILETIME CreationTime;
		pInput->Store(&CreationTime);
		// Set the file creation time
		BOOL bFileInfoResult = SetFileTime(fp,&CreationTime,NULL,NULL);
		if (bFileInfoResult) {
			uResult = OKAY;
		}
	}
	return uResult;
}
开发者ID:cometdlut,项目名称:burgerlib,代码行数:15,代码来源:brfilexbox360.cpp

示例5: hugsprim_SetFileTime_12

static void hugsprim_SetFileTime_12(HugsStackPtr hugs_root)
{
    HsPtr arg1;
    HsPtr arg2;
    HsPtr arg3;
    HsPtr arg4;
    HsBool res1;
    arg1 = hugs->getPtr();
    arg2 = hugs->getPtr();
    arg3 = hugs->getPtr();
    arg4 = hugs->getPtr();
    res1 = SetFileTime(arg1, arg2, arg3, arg4);
    hugs->putBool(res1);
    hugs->returnIO(hugs_root,1);
}
开发者ID:xpika,项目名称:winhugs,代码行数:15,代码来源:Time.c

示例6: changeFileDate

void changeFileDate(const std::string& filename, uLong dosdate, tm_unz tmu_date)
{
#ifdef _WIN32
	HANDLE hFile;
	FILETIME ftm, ftLocal, ftCreate, ftLastAcc, ftLastWrite;

	hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
		DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
		LocalFileTimeToFileTime(&ftLocal, &ftm);
		SetFileTime(hFile, &ftm, &ftLastAcc, &ftm);
		CloseHandle(hFile);
	}
开发者ID:DouglasHeriot,项目名称:zipper,代码行数:15,代码来源:tools.cpp

示例7: format

  /* change_file_date : change the date/time of a file
     filename : the filename of the file where date/time must be modified
     dosdate : the new date at the MSDos format (4 bytes)
     tmu_date : the SAME new date at the tm_unz format */
  static void change_file_date( const wchar_t *filename, uLong dosdate, tm_unz tmu_date )
  {
#if defined(_WIN32) || defined (_WIN64)
    HANDLE hFile;
    FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;

    hFile = CreateFileW(filename,GENERIC_READ | GENERIC_WRITE,
                        0,NULL,OPEN_EXISTING,0,NULL);
    GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
    DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
    LocalFileTimeToFileTime(&ftLocal,&ftm);
    SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
    CloseHandle(hFile);
#endif
  }
开发者ID:ONLYOFFICE,项目名称:core,代码行数:19,代码来源:ZipUtilsCP.cpp

示例8: ULTRACOPIER_DEBUGCONSOLE

bool MkPath::writeFileDateTime(const QFileInfo &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"writeFileDateTime("+destination.absoluteFilePath()+")");
    /** Why not do it with Qt? Because it not support setModificationTime(), and get the time with Qt, that's mean use local time where in C is UTC time */
    #ifdef Q_OS_UNIX
        #ifdef Q_OS_LINUX
            return utime(destination.absoluteFilePath().toLatin1().data(),&butime)==0;
        #else //mainly for mac
            return utime(destination.absoluteFilePath().toLatin1().data(),&butime)==0;
        #endif
    #else
        #ifdef Q_OS_WIN32
            #ifdef ULTRACOPIER_PLUGIN_SET_TIME_UNIX_WAY
                return utime(destination.toLatin1().data(),&butime)==0;
            #else
                wchar_t filePath[65535];
                if(destination.absoluteFilePath().contains(regRead))
                    filePath[QDir::toNativeSeparators(QStringLiteral("\\\\?\\")+destination.absoluteFilePath()).toWCharArray(filePath)]=L'\0';
                else
                    filePath[QDir::toNativeSeparators(destination.absoluteFilePath()).toWCharArray(filePath)]=L'\0';
                HANDLE hFileDestination = CreateFileW(filePath, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
                if(hFileDestination == INVALID_HANDLE_VALUE)
                {
                    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"open failed to write: "+QString::fromWCharArray(filePath)+", error: "+QString::number(GetLastError()));
                    return false;
                }
                FILETIME ftCreate, ftAccess, ftWrite;
                ftCreate.dwLowDateTime=this->ftCreateL;
                ftCreate.dwHighDateTime=this->ftCreateH;
                ftAccess.dwLowDateTime=this->ftAccessL;
                ftAccess.dwHighDateTime=this->ftAccessH;
                ftWrite.dwLowDateTime=this->ftWriteL;
                ftWrite.dwHighDateTime=this->ftWriteH;
                if(!SetFileTime(hFileDestination, &ftCreate, &ftAccess, &ftWrite))
                {
                    CloseHandle(hFileDestination);
                    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to set the file time");
                    return false;
                }
                CloseHandle(hFileDestination);
                return true;
            #endif
        #else
            return false;
        #endif
    #endif
    return false;
}
开发者ID:amitamitamitamit,项目名称:Ultracopier,代码行数:48,代码来源:MkPath.cpp

示例9: CWE506_Embedded_Malicious_Code__w32_file_attrib_created_10_bad

void CWE506_Embedded_Malicious_Code__w32_file_attrib_created_10_bad()
{
    if(globalTrue)
    {
        {
            FILETIME ftCreate;
            ULONGLONG qwResult;
            HANDLE hFile = INVALID_HANDLE_VALUE;
            do
            {
                hFile = CreateFile(TEXT("badFile.txt"),
                                   GENERIC_READ | GENERIC_WRITE, /* needed for SetFileTime to work properly */
                                   0,
                                   NULL,
                                   CREATE_ALWAYS,
                                   FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile == INVALID_HANDLE_VALUE)
                {
                    break;
                }
                if (GetFileTime(hFile,
                                &ftCreate,
                                NULL,
                                NULL) == 0)
                {
                    break;
                }
                /* adapted from http://support.microsoft.com/kb/188768 */
                qwResult = (((ULONGLONG) ftCreate.dwHighDateTime) << 32) + ftCreate.dwLowDateTime;
                /* Subtract 10 days from real creation date */
                qwResult -= 10 * _DAY;
                /* Copy result back into ftCreate */
                ftCreate.dwLowDateTime  = (DWORD)(qwResult & 0xFFFFFFFF);
                ftCreate.dwHighDateTime = (DWORD)(qwResult >> 32);
                /* FLAW: Modify the file's creation time */
                SetFileTime(hFile,
                            &ftCreate,
                            (LPFILETIME)NULL,
                            (LPFILETIME)NULL);
            }
            while (0);
            if (hFile != INVALID_HANDLE_VALUE)
            {
                CloseHandle(hFile);
            }
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:48,代码来源:CWE506_Embedded_Malicious_Code__w32_file_attrib_created_10.c

示例10: ExtractStreams

void ExtractStreams(Archive &Arc,const wchar *FileName,bool TestMode)
{
  wchar FullName[NM+2];
  if (FileName[0]!=0 && FileName[1]==0)
  {
    wcscpy(FullName,L".\\");
    wcsncpyz(FullName+2,FileName,ASIZE(FullName)-2);
  }
  else
    wcsncpyz(FullName,FileName,ASIZE(FullName));

  byte *Data=&Arc.SubHead.SubData[0];
  size_t DataSize=Arc.SubHead.SubData.Size();

  wchar StreamName[NM];
  GetStreamNameNTFS(Arc,StreamName,ASIZE(StreamName));
  if (*StreamName!=':')
  {
    uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
    ErrHandler.SetErrorCode(RARX_CRC);
    return;
  }

  if (TestMode)
  {
    Arc.ReadSubData(NULL,NULL);
    return;
  }

  wcsncatz(FullName,StreamName,ASIZE(FullName));

  FindData fd;
  bool Found=FindFile::FastFind(FileName,&fd);

  if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
    SetFileAttr(FileName,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
  File CurFile;
  if (CurFile.WCreate(FullName) && Arc.ReadSubData(NULL,&CurFile))
    CurFile.Close();
  File HostFile;
  if (Found && HostFile.Open(FileName,FMF_OPENSHARED|FMF_UPDATE))
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
                &fd.ftLastWriteTime);

  // Restoring original file attributes. Important if file was read only
  // or did not have "Archive" attribute
  SetFileAttr(FileName,fd.FileAttr);
}
开发者ID:Cpasjuste,项目名称:nzbm,代码行数:48,代码来源:win32stm.cpp

示例11: SetFileTime

void File::SetOpenFileTime(RarTime *ftm,RarTime *ftc,RarTime *fta)
{
#ifdef _WIN_32
  bool sm=ftm!=NULL && ftm->IsSet();
  bool sc=ftc!=NULL && ftc->IsSet();
  bool sa=fta!=NULL && fta->IsSet();
  FILETIME fm,fc,fa;
  if (sm)
    ftm->GetWin32(&fm);
  if (sc)
    ftc->GetWin32(&fc);
  if (sa)
    fta->GetWin32(&fa);
  SetFileTime(hFile,sc ? &fc:NULL,sa ? &fa:NULL,sm ? &fm:NULL);
#endif
}
开发者ID:chicken1337,项目名称:kx-audio-driver,代码行数:16,代码来源:file.cpp

示例12: SetFileTime

/**
this is not needed for bulk_extractor
*/
void File::SetOpenFileTime(RarTime *ftm,RarTime *ftc,RarTime *fta)
{ //We probably don't need to worry about this at all
#ifdef _WIN_ALL
  bool sm=ftm!=NULL && ftm->IsSet();
  bool sc=ftc!=NULL && ftc->IsSet();
  bool sa=fta!=NULL && fta->IsSet();
  FILETIME fm,fc,fa;
  if (sm)
    ftm->GetWin32(&fm);
  if (sc)
    ftc->GetWin32(&fc);
  if (sa)
    fta->GetWin32(&fa);
  SetFileTime(hFile,sc ? &fc:NULL,sa ? &fa:NULL,sm ? &fm:NULL);
#endif
}
开发者ID:ajnelson,项目名称:bulk_extractor,代码行数:19,代码来源:file.cpp

示例13: setfiletime

static int setfiletime (const TCHAR *name, int days, int minute, int tick, int tolocal)
{
	FILETIME LocalFileTime, FileTime;
	HANDLE hFile;
	const TCHAR *namep;
	TCHAR path[MAX_DPATH];
	
	if (currprefs.win32_filesystem_mangle_reserved_names == false) {
		_tcscpy (path, PATHPREFIX);
		_tcscat (path, name);
		namep = path;
	} else {
		namep = name;
	}

	if ((hFile = CreateFile (namep, GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)) == INVALID_HANDLE_VALUE)
		return 0;

	for (;;) {
		ULARGE_INTEGER lft;

		lft.QuadPart = (((uae_u64)(377*365+91+days)*(uae_u64)1440+(uae_u64)minute)*(uae_u64)(60*50)+(uae_u64)tick)*(uae_u64)200000;
		LocalFileTime.dwHighDateTime = lft.HighPart;
		LocalFileTime.dwLowDateTime = lft.LowPart;
		if (tolocal) {
			if (!LocalFileTimeToFileTime (&LocalFileTime, &FileTime))
				FileTime = LocalFileTime;
		} else {
			FileTime = LocalFileTime;
		}
		if (!SetFileTime (hFile, &FileTime, &FileTime, &FileTime)) {
			if (days > 47846) { // > 2108-12-31 (fat limit)
				days = 47846;
				continue;
			}
			if (days < 730) { // < 1980-01-01 (fat limit)
				days = 730;
				continue;
			}
		}
		break;
	}

	CloseHandle (hFile);

	return 1;
}
开发者ID:engur,项目名称:WinUAE,代码行数:47,代码来源:fsdb_mywin32.cpp

示例14: do_SetFileTime

static int do_SetFileTime(int argc, wchar_t **argv)
{
    if (argc != 5)
        fail("usage: SetFileTime FileName CreationTime LastAccessTime LastWriteTime");
    HANDLE h = CreateFileW(argv[1],
        FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);
    if (INVALID_HANDLE_VALUE == h)
        errprint(0);
    else
    {
        FILETIME *CreationTime = 0, *LastAccessTime = 0, *LastWriteTime = 0, ft[3];
        SYSTEMTIME systime;
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[2], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[0]))
                CreationTime = &ft[0];
        }
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[3], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[1]))
                LastAccessTime = &ft[1];
        }
        memset(&systime, 0, sizeof systime);
        systime.wMonth = systime.wDay = 1;
        if (0 < swscanf(argv[4], L"%hd-%02hd-%02hdT%02hd:%02hd:%02hd",
            &systime.wYear, &systime.wMonth, &systime.wDay,
            &systime.wHour, &systime.wMinute, &systime.wSecond))
        {
            if (SystemTimeToFileTime(&systime, &ft[2]))
                LastWriteTime = &ft[2];
        }
        BOOL r = SetFileTime(h, CreationTime, LastAccessTime, LastWriteTime);
        errprint(r);
        CloseHandle(h);
    }
    return 0;
}
开发者ID:nkzxw,项目名称:winfstest,代码行数:46,代码来源:winfstest.c

示例15: win_utimes

CAMLprim value win_utimes (value path, value wpath, value atime, value mtime) {
  HANDLE h;
  BOOL res;
  ULARGE_INTEGER iatime, imtime;
  FILETIME fatime, fmtime;

  CAMLparam4(path, wpath, atime, mtime);

  iatime.QuadPart = Double_val(atime);
  imtime.QuadPart = Double_val(mtime);

  /* http://www.filewatcher.com/p/Win32-UTCFileTime-1.44.tar.gz.93147/Win32-UTCFileTime-1.44/UTCFileTime.xs.html */
  /* http://savannah.nongnu.org/bugs/?22781#comment0 */
  if (iatime.QuadPart || imtime.QuadPart) {
    iatime.QuadPart += 11644473600ull;
    iatime.QuadPart *= 10000000ull;
    fatime.dwLowDateTime = iatime.LowPart;
    fatime.dwHighDateTime = iatime.HighPart;
    imtime.QuadPart += 11644473600ull;
    imtime.QuadPart *= 10000000ull;
    fmtime.dwLowDateTime = imtime.LowPart;
    fmtime.dwHighDateTime = imtime.HighPart;
  } else {
    GetSystemTimeAsFileTime (&fatime);
    fmtime = fatime;
  }
  h = CreateFileW ((LPWSTR) wpath, FILE_WRITE_ATTRIBUTES,
		   FILE_SHARE_READ | FILE_SHARE_WRITE,
		   NULL, OPEN_EXISTING, 0, NULL);
  if (h == INVALID_HANDLE_VALUE) {
    win32_maperr (GetLastError ());
    uerror("utimes", path);
  }
  res = SetFileTime (h, NULL, &fatime, &fmtime);
  if (res == 0) {
    win32_maperr (GetLastError ());
    (void)CloseHandle (h);
    uerror("utimes", path);
  }
  res = CloseHandle (h);
  if (res == 0) {
    win32_maperr (GetLastError ());
    uerror("utimes", path);
  }
  CAMLreturn (Val_unit);
}
开发者ID:Phylliade,项目名称:Unison,代码行数:46,代码来源:system_win_stubs.c


注:本文中的SetFileTime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。