Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Ich habe das Erstellungsdatum einer Datei ausgelesen, und möchte dieses als Dateinamen einer neuen Datei verwenden, also z.B.: 02062005.txt

Wie kann ich den Double Wert, in das antsprechende Format umwandeln?


struct stat buf;

stat(fileread, &buf);

double datum = buf.st_atime;

char String TimeToStr(double datum);

char filewrite = String;

Ich dachte mit DateToStr ginge das sehr einfach, jedoch erzeuge ich nur Fehlermeldungen.

Die Funktion gehört zur Klasse TDateTime (aus include/vcl/sysdefs.h) Leider steht mir diese Bibliothek nicht zur Verfügung. Da habe ich gehofft, mir kann jemand von hier weiterhelfen.

Ich habe es jetzt folgendermaßen versucht, bekomme aber immer nur das heutige Datum, und nicht das Datum des Files angezeigt:


time_t timer;

struct tm *tblock;	// Erhält die Tageszeit

tblock = localtime(&buf.st_atime);


sprintf(filewrite,"%02d %02d %04d.txt",tblock->tm_mday,tblock->tm_mon+1,tblock->tm_year+1900);

Nein, hast Du einen Link zum MSDN Beispiel?

ich vermute mal, das Beispiel ist gewünscht:

Example

// crt_stat.c

/* This program uses the _stat64 function to

* report information about the file named stat.c.

*/

#include <time.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <stdio.h>

int main( void )

{

struct __stat64 buf;

int result;

/* Get data associated with "crt_stat.c": */

result = _stat64( "crt_stat.c", &buf );

/* Check if statistics are valid: */

if( result != 0 )

perror( "Problem getting information" );

else

{

/* Output some of the statistics: */

printf( "File size : %ld\n", buf.st_size );

printf( "Drive : %c:\n", buf.st_dev + 'A' );

printf( "Time modified : %s", _ctime64( &buf.st_mtime ) );

}

}

Sample Output

File size : 732

Drive : C:

Time modified : Thu Feb 07 14:39:36 2002

copyright msdn :floet:

  • 3 Wochen später...

Also die Ausgabe funktioniert ja auch wunderbar. Ich kann den String jedoch nicht als Dateinamen verwenden. Beim Kompilieren erhalte ich immer eine Fehlermeldung. (Cannot convert 'char *' to 'char[]' in function main())

struct stat buf;

stat(fileread, &buf);

int groesse = buf.st_size;

cout<< ("Erstellungsdatum : %s", ctime( &buf.st_mtime ) );

char filewrite[] = ("CUT %s", ctime( &buf.st_mtime) );

Vorher hatte ich immer eine Eingabe, die ich nun weglassen will, weil das datum in meinem Fall eine Eindeutige Zuordnung für die datei darstellen würde.

Das es Quatsch ist, habe ich ja schon bemerkt.

Ich will halt einfach meiner datei, die ich schreibe das Datum zuweisen, das ich aus einer anderen Datei auslese. Das auslesen funktioniert ja auch. Die Anzeige mit:

cout<< ("Erstellungsdatum : %s", ctime( &buf.st_mtime ) );

ebenso. Mein Gedanke war, wenn ich die Zeile so am Bildschirm ausgeben kann, kann ich die auch in meine Variable filewrite packen, und habe den Dateinamen. Also wo hinke ich? Wenn ich folgenden Code verwende:
sprintf(filewrite,"CUT %s.txt",ctime (&buf.st_mtime));

Erhalte ich nach Programmablauf sogar die Meldung, dass meione Datei unter dem Namen:" CUT Thu Feb 07 14:39:36 2002" gespeichert wurde.

Jedoch ist die Datei nicht vorhanden....

Habe jetzt mal eine Weile rumgespielt und ältere und bereits verworfene Codefragmente untersucht, und hab folgende Lösung gefunden:

struct tm *tblock;

tblock = localtime( &buf.st_mtime );

sprintf(filewrite,"CUT %02d %02d %04d.txt",tblock->tm_mday-1,tblock->tm_mon+1,tblock->tm_year+1900);


Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.