Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:38:18+00:00 2026-06-01T10:38:18+00:00

I have the following code: int main(int argc, char** argv) { onelog a; std::cout

  • 0

I have the following code:

int main(int argc, char** argv) {
    onelog a;
    std::cout << "a new project";

    //creates a file as varuntest.txt
    ofstream file("C:\\users\\Lenovo\\Documents\\varuntest.txt", ios::app);

    SYSTEMTIME thesystemtime;
    GetSystemTime(&thesystemtime);

    thesystemtime.wDay = 07;//changes the day
    thesystemtime.wMonth = 04;//changes the month
    thesystemtime.wYear = 2012;//changes the year

    //creation of a filetimestruct and convert our new systemtime
    FILETIME thefiletime;

    SystemTimeToFileTime(&thesystemtime,&thefiletime);

    //getthe handle to the file
    HANDLE filename = CreateFile("C:\\users\\Lenovo\\Documents\\varuntest.txt", 
                                FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE,
                                NULL, OPEN_EXISTING, 
                                FILE_ATTRIBUTE_NORMAL, NULL);

    //set the filetime on the file
    SetFileTime(filename,(LPFILETIME) NULL,(LPFILETIME) NULL,&thefiletime);

    //close our handle.
    CloseHandle(filename);


    return 0;
}

Now the question is; it only changes the modified date when I check the properties of the file. I need to ask;

How to change the file’s creation date instead of the modification
date?

Thanks

Please give some code for this novice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:38:19+00:00Added an answer on June 1, 2026 at 10:38 am

    It sets the last modified time because that’s what you asked it to do. The function receives 3 filetime parameters and you only passed a value to the final one, lpLastWriteTime. To set the creation time call the function like this:

    SetFileTime(filename, &thefiletime, (LPFILETIME) NULL,(LPFILETIME) NULL);
    

    I suggest you take a read of the documentation for SetFileTime. The key part is its signature which is as follows:

    BOOL WINAPI SetFileTime(
      __in      HANDLE hFile,
      __in_opt  const FILETIME *lpCreationTime,
      __in_opt  const FILETIME *lpLastAccessTime,
      __in_opt  const FILETIME *lpLastWriteTime
    );
    

    Since you say that you are a novice with the Windows API I’ll give you a tip. The documentation on MSDN is very comprehensive. Whenever you get stuck with a Win32 API call, look it up on MSDN.

    And some comments on your code:

    • You should always check the return values for any API calls. If you call the functions incorrectly, or they fail for some other reason, you’ll find it impossible to work out what went wrong without error checking.
    • The variable that you call filename should in fact be named fileHandle.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have the following code: int main(int argc, char** argv) { Foo f;
I have the following code: #include <stdio.h> main(int argc, char *argv[]) { int n,st;
I have the following code: #define INPUT_FILE -i int main(int argc, char* argv[]) {
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following code: template<int k> void foo() { } int main(int argc,
I have the following piece of code: #include <stdio.h> #include <stdlib.h> int main(int argc,
I have the following c++ code: #include <iostream> #include <string> int main( int argc,
So I have the following test code: #include <string.h> #include <stdio.h> int main(int argc,
I have the following piece of code: #include <stdio.h> int main ( int argc,
I have the following code int main() { int a=6; void *p; p=&a; p++;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.