<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[ofstream] timestamp aktualisieren]]></title><description><![CDATA[<p>wie kann man am elegantesten (also ohne close und open) den Zeitstempel einer Datei aktualisieren?</p>
<p>Windowsbeispiel</p>
<pre><code class="language-cpp">std::ofstream logFile(&quot;log.txt&quot;);

::Sleep(7000);
logFile &lt;&lt; &quot;logInfo1\n&quot;;
logFile.flush(); //&lt;- Datei wird aktualisiert, Zeitstempel leider nicht

::Sleep(7000);
logFile.close(); //&lt;- Zeitstempel wird aktualsiert
</code></pre>
<p>Im Dateiexplorer wird erst bei close die aktuelle Zeit angegeben.<br />
Problem ist, dass ich via Dateimonitor die Logs betrachte, die jedoch anstelle eines &quot;Reload&quot; den Zeitstempel der Datei zur Dateiänderung betrachten.</p>
<p>Gibt es einen Weg OHNE close und open dieses Problem zu lösen?</p>
<p>--SirAnn</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271425/ofstream-timestamp-aktualisieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 13:41:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271425.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Jul 2010 07:04:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [ofstream] timestamp aktualisieren on Wed, 28 Jul 2010 07:04:08 GMT]]></title><description><![CDATA[<p>wie kann man am elegantesten (also ohne close und open) den Zeitstempel einer Datei aktualisieren?</p>
<p>Windowsbeispiel</p>
<pre><code class="language-cpp">std::ofstream logFile(&quot;log.txt&quot;);

::Sleep(7000);
logFile &lt;&lt; &quot;logInfo1\n&quot;;
logFile.flush(); //&lt;- Datei wird aktualisiert, Zeitstempel leider nicht

::Sleep(7000);
logFile.close(); //&lt;- Zeitstempel wird aktualsiert
</code></pre>
<p>Im Dateiexplorer wird erst bei close die aktuelle Zeit angegeben.<br />
Problem ist, dass ich via Dateimonitor die Logs betrachte, die jedoch anstelle eines &quot;Reload&quot; den Zeitstempel der Datei zur Dateiänderung betrachten.</p>
<p>Gibt es einen Weg OHNE close und open dieses Problem zu lösen?</p>
<p>--SirAnn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932906</guid><dc:creator><![CDATA[muffmolch]]></dc:creator><pubDate>Wed, 28 Jul 2010 07:04:08 GMT</pubDate></item><item><title><![CDATA[Reply to [ofstream] timestamp aktualisieren on Wed, 28 Jul 2010 07:15:44 GMT]]></title><description><![CDATA[<p>Plattformabhängig geht das auf jeden Fall (unter Windows z.B. <a href="http://msdn.microsoft.com/en-us/library/ms724933%28VS.85%29.aspx" rel="nofollow">SetFileTime</a>).<br />
Plattformunabhängig ohne externe Bibliotheken bezweifle ich aber, da im Standard gar nicht davon ausgegangen wird, dass Dateien überhaupt einen Zeitstempel haben.</p>
<p>Wahrscheinlich ist aber ein reopen hier das einfachste.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932913</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Wed, 28 Jul 2010 07:15:44 GMT</pubDate></item><item><title><![CDATA[Reply to [ofstream] timestamp aktualisieren on Wed, 28 Jul 2010 09:14:24 GMT]]></title><description><![CDATA[<p>ok. Danke für die Antwort. Ich besorge mir nun mit Create_File einen Handle und ändere über diesen dann den Zeitstempel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932963</guid><dc:creator><![CDATA[muffmolch]]></dc:creator><pubDate>Wed, 28 Jul 2010 09:14:24 GMT</pubDate></item><item><title><![CDATA[Reply to [ofstream] timestamp aktualisieren on Wed, 28 Jul 2010 09:28:23 GMT]]></title><description><![CDATA[<p>Ein Projekt dass ich vor langer Zeit programmiert habe:</p>
<pre><code class="language-cpp">// std::
#include &lt;iostream&gt; 
#include &lt;ctime&gt;
#include &lt;string&gt;
#include &lt;cstring&gt;
#include &lt;cstdio&gt;
// Windows::
#include &lt;windows.h&gt;
#include &lt;wincon.h&gt;
#include &lt;shlwapi.h&gt;
#include &lt;conio.h&gt;
void askInformations();
void getFilesInDir(const std::string&amp;, const SYSTEMTIME&amp;);
void setFileTime(const std::string&amp;, const SYSTEMTIME&amp;);
void handleError(const std::string&amp;);

int main()
{

	// BOOL WINAPI SetConsoleTitle(
	//   __in  LPCTSTR lpConsoleTitle
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms686050(v=VS.85).aspx
	if(!SetConsoleTitle(&quot;Die Zeitmaschine für Dateien&quot;))
		handleError(&quot;SetConsoleTitle&quot;);

	// HANDLE WINAPI GetStdHandle(
	//  __in  DWORD nStdHandle
	//  ); -&gt; http://msdn.microsoft.com/en-us/library/ms683231(v=VS.85).aspx
	HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);

	if(outHandle == INVALID_HANDLE_VALUE)	
		handleError(&quot;GetStdHandle&quot;);
	// BOOL WINAPI SetConsoleTextAttribute(
	//   __in  HANDLE hConsoleOutput,
	//   __in  WORD wAttributes
	//  ); -&gt; http://msdn.microsoft.com/en-us/library/ms686047(v=VS.85).aspx
	if(!SetConsoleTextAttribute(outHandle, FOREGROUND_GREEN))
	       handleError(&quot;SetConsoleTextAttribute&quot;);

	askInformations();
	fflush(stdin);
	std::cin.get();
	return 0;
}

void askInformations()
{
	std::string pathToFiles;
	char answer;
	do
	{
		std::wcout &lt;&lt; L&quot;Pfad zum Ordner eingeben (C:\\Users\\...) : &quot;;
		std::getline(std::cin, pathToFiles, '\n');
		fflush(stdin);
		// BOOL PathIsDirectory(__in LPCTSTR pszPath); -&gt; http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
		//if(!PathIsDirectory(pathToFiles.c_str())) {
		//	std::cerr &lt;&lt; &quot;Error: \&quot;&quot; &lt;&lt; pathToFiles &lt;&lt; &quot;\&quot; ist kein Ordner.\nBitte Pfad zum Ordner neu eingeben.&quot; &lt;&lt; std::endl;
		//	continue;
		//}
		// PathIsDirectory has a bug under Win7, so I don't use it...

		std::cout &lt;&lt; &quot;Ist dieser Pfad richtig \&quot;&quot; &lt;&lt; pathToFiles &lt;&lt; &quot;\&quot; (J/N) ?&quot; &lt;&lt; std::endl;
		std::cin.get(answer);
		fflush(stdin);
	}while(answer != 'J' &amp;&amp; answer != 'j');

	SYSTEMTIME newTime_sysTime = { 0 };
	do
	{
		std::cout &lt;&lt; &quot;Zur welcher Zeit soll das Erstelldatum gesetzt werden?&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;Tag: &quot;;
		std::cin &gt;&gt; newTime_sysTime.wDay;
		fflush(stdin);
		std::cout &lt;&lt; &quot;Monat: &quot;;
		std::cin &gt;&gt; newTime_sysTime.wMonth;
		fflush(stdin);
		std::cout &lt;&lt; &quot;Jahr: &quot;;
		std::cin &gt;&gt; newTime_sysTime.wYear;
		fflush(stdin);
		std::cout &lt;&lt; &quot;\n\nIst das Datum richtig \&quot;&quot; &lt;&lt; newTime_sysTime.wDay &lt;&lt; &quot;.&quot;
							&lt;&lt; newTime_sysTime.wMonth &lt;&lt; &quot;.&quot;
							&lt;&lt; newTime_sysTime.wYear &lt;&lt; &quot;\&quot; (J/N)?&quot; &lt;&lt; std::endl;
		std::cin.get(answer);
		fflush(stdin);
	}while(answer != 'J' &amp;&amp; answer != 'j');

	getFilesInDir(pathToFiles, newTime_sysTime);	
}

void getFilesInDir(const std::string&amp; pathToFiles, const SYSTEMTIME&amp; newTime_sysTime)
{

	HANDLE handle;  
	// typedef struct _WIN32_FIND_DATA {
	//   DWORD    dwFileAttributes;
	//   FILETIME ftCreationTime;
	//   FILETIME ftLastAccessTime;
	//   FILETIME ftLastWriteTime;
	//   DWORD    nFileSizeHigh;
	//   DWORD    nFileSizeLow;
	//   DWORD    dwReserved0;
	//   DWORD    dwReserved1;
	//   TCHAR    cFileName[MAX_PATH];
	//   TCHAR    cAlternateFileName[14];
	//   } WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA; -&gt; http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx
	WIN32_FIND_DATA findHandle;
	// HANDLE WINAPI FindFirstFile(
	//   __in   LPCTSTR lpFileName,
	//   __out  LPWIN32_FIND_DATA lpFindFileData
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
	handle=FindFirstFile((pathToFiles + std::string(&quot;\\*&quot;)).c_str(), &amp;findHandle);  
	// BOOL WINAPI FindNextFile(
	//   __in   HANDLE hFindFile,
	//   __out  LPWIN32_FIND_DATA lpFindFileData
	//  ); -&gt; http://msdn.microsoft.com/en-us/library/aa364428(v=VS.85).aspx
	FindNextFile(handle,&amp;findHandle);  
	while (FindNextFile(handle,&amp;findHandle))  
		if (!(findHandle.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY))
		{
			std::cout &lt;&lt; &quot;[DEBUG-getFilesInDir] &quot; &lt;&lt; findHandle.cFileName &lt;&lt; std::endl;
			setFileTime(pathToFiles + std::string(&quot;\\&quot;) + std::string(findHandle.cFileName), newTime_sysTime);
		}
  	// BOOL WINAPI CloseHandle(
	//   __in  HANDLE hObject
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx
	FindClose(handle); 
}

void setFileTime(const std::string&amp; fileName, const SYSTEMTIME&amp; newFileTime_sysTime)
{
	std::cout &lt;&lt; &quot;[DEBUG-setFileTime] &quot; &lt;&lt; fileName &lt;&lt; std::endl;
	// HANDLE WINAPI CreateFile(
	//   __in      LPCTSTR lpFileName,
	//   __in      DWORD dwDesiredAccess,
	//   __in      DWORD dwShareMode,
	//   __in_opt  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
	//   __in      DWORD dwCreationDisposition,
	//   __in      DWORD dwFlagsAndAttributes,
	//   __in_opt  HANDLE hTemplateFile
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx
	HANDLE fileHandle = CreateFile(
					fileName.c_str(),
					GENERIC_READ | GENERIC_WRITE,
					FILE_SHARE_READ | FILE_SHARE_WRITE,
					NULL,
					OPEN_EXISTING,
					FILE_ATTRIBUTE_NORMAL,
					NULL
				      );
	if(fileHandle == INVALID_HANDLE_VALUE)
		handleError(&quot;CreateFile&quot;);	

	// typedef struct _FILETIME {
	//   DWORD dwLowDateTime;
	//   DWORD dwHighDateTime;
	//   } FILETIME, *PFILETIME; -&gt; http://msdn.microsoft.com/en-us/library/ms724284(v=VS.85).aspx
	FILETIME creationTime_fileTime;

	// BOOL WINAPI GetFileTime(
	//   __in       HANDLE hFile,
	//   __out_opt  LPFILETIME lpCreationTime,
	//   __out_opt  LPFILETIME lpLastAccessTime,
	//   __out_opt  LPFILETIME lpLastWriteTime
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms724320(v=VS.85).aspx
	if(!GetFileTime(fileHandle, &amp;creationTime_fileTime, NULL, NULL))
		handleError(&quot;GetFileTime&quot;);

	// typedef struct _SYSTEMTIME {
	//   WORD wYear;
	//   WORD wMonth;
	//   WORD wDayOfWeek;
	//   WORD wDay;
	//   WORD wHour;
	//   WORD wMinute;
	//   WORD wSecond;
	//   WORD wMilliseconds;
	//   } SYSTEMTIME, *PSYSTEMTIME; -&gt; http://msdn.microsoft.com/en-us/library/ms724950(v=VS.85).aspx
	SYSTEMTIME creationTime_sysTime;

	// BOOL WINAPI FileTimeToSystemTime(
	//   __in   const FILETIME *lpFileTime,
	//   __out  LPSYSTEMTIME lpSystemTime
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms724280(v=VS.85).aspx
	if(!FileTimeToSystemTime(&amp;creationTime_fileTime, &amp;creationTime_sysTime))
	       handleError(&quot;FileTimeToSystemTime&quot;);

	std::cout &lt;&lt; &quot;Die Datei \&quot;&quot; &lt;&lt; fileName.c_str() &lt;&lt; &quot;\&quot; wurde am: \&quot;&quot; 
		&lt;&lt; creationTime_sysTime.wDay 
		&lt;&lt; &quot;.&quot; &lt;&lt; creationTime_sysTime.wMonth
		&lt;&lt; &quot;.&quot; &lt;&lt; creationTime_sysTime.wYear &lt;&lt; &quot;\&quot; erstellt.&quot; &lt;&lt; std::endl;

	// BOOL WINAPI SystemTimeToFileTime(
	//   __in   const SYSTEMTIME *lpSystemTime,
	//   __out  LPFILETIME lpFileTime
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms724948(VS.85).aspx
	if(!SystemTimeToFileTime(&amp;newFileTime_sysTime, &amp;creationTime_fileTime))
		handleError(&quot;SystemTimeToFileTime&quot;);

	// BOOL WINAPI SetFileTime(
	//   __in      HANDLE hFile,
	//   __in_opt  const FILETIME *lpCreationTime,
	//   __in_opt  const FILETIME *lpLastAccessTime,
	//   __in_opt  const FILETIME *lpLastWriteTime
	//   ); -&gt; http://msdn.microsoft.com/en-us/library/ms724933(v=VS.85).aspx
	if(!SetFileTime(fileHandle, &amp;creationTime_fileTime, NULL, NULL))
		handleError(&quot;SetFileTime&quot;);

	std::wcout &lt;&lt; L&quot;Erfolgreich geändert in: &quot;  
	        &lt;&lt; newFileTime_sysTime.wDay 
		&lt;&lt; L&quot;.&quot; &lt;&lt; newFileTime_sysTime.wMonth
		&lt;&lt; L&quot;.&quot; &lt;&lt; newFileTime_sysTime.wYear &lt;&lt; std::endl;

	CloseHandle(fileHandle);
}

void handleError(const std::string&amp; functionCall)
{
	std::cerr &lt;&lt; &quot;[FUNCTION] &quot; &lt;&lt; functionCall &lt;&lt; std::endl;
	// DWORD WINAPI GetLastError(void); -&gt; http://msdn.microsoft.com/en-us/library/ms679360(v=VS.85).aspx
	int ErrorCode = GetLastError();
	std::wcerr &lt;&lt; L&quot;\nErrorcode: &quot; &lt;&lt; ErrorCode 
				&lt;&lt; L&quot;\nBitte rufen Sie den Entwickler „“ an &quot; 
				&lt;&lt; L&quot;oder schicken Sie ihm eine E-Mail an „“ &quot;
				&lt;&lt; L&quot;und teilen Sie ihm den Errorcode mit. - Danke.\n&quot; &lt;&lt; std::endl;

	std::wcout &lt;&lt; L&quot;Bitte betätigen Sie eine Taste um das Programm zu schließen...&quot; &lt;&lt; std::endl;
	std::cin.get();
	exit(ErrorCode);
}
</code></pre>
<p>Ziemlich hässlich wie ich jetzt finde. aber bin der winapi näher gekommen.<br />
€dit: Für dich wird wahrscheinlich nur die setFileTime-Funktion von Bedeutung sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932970</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Wed, 28 Jul 2010 09:28:23 GMT</pubDate></item></channel></rss>