Solved

Move a File

Posted on 2004-04-19
8
742 Views
Last Modified: 2013-11-20
Hi

I am using ::MoveFile(sFrom, sTo) to move and re-name a file, which works ok but my problem is when the file is moved its Date Created is changed to the time it's moved. How can I move the file and keep the orginal creation date
0
Comment
Question by:Dj_Fx8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:leflon
ID: 10858915
Hi Dj_Fx8,

i'm not sure about a change in creation date (will check this), but maybe you are better of with the duo of
  CopyFile(org,new)
and
  DeleteFile(org)

leflon
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 10858981
Try SHFileOperation with FO_MOVE operation. This function is called by Windows Explorer. Explorer Move function doesn't change creation date.
0
 
LVL 7

Expert Comment

by:leflon
ID: 10859038
Dj_Fx8,
yepp, CopyFile() modifies the date the same way MoveFile did, sorry.
AlexFM's comment sounds good (will try it now too :) )

leflon
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dj_Fx8
ID: 10860028
Ok whats wrong with this, for every file it says Cannot move file: Cannot read from the source file or disk. but the files are there ok ???

      SHFILEOPSTRUCT  lpFileOp;
      lpFileOp.hwnd = pParent;
      lpFileOp.wFunc = FO_MOVE;
      lpFileOp.pFrom = sFrom;
      lpFileOp.pTo = sTo;
      lpFileOp.fFlags = FOF_RENAMEONCOLLISION | FOF_SILENT;
      lpFileOp.fAnyOperationsAborted = FALSE;
      lpFileOp.hNameMappings = NULL;
      lpFileOp.lpszProgressTitle = NULL;

      if (!SHFileOperation(&lpFileOp))
            return TRUE;

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10860068
lpFileOp.pFrom = sFrom;

pFrom
Address of a buffer to specify one or more source file names. Although this member is declared as a null-terminated string, it is used as a buffer to hold multiple file names. Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom.

0
 

Author Comment

by:Dj_Fx8
ID: 10860435
So what your saying is I have to add NULL on to the end of sFrom, as sTo can also contain a list of files do I need to add a NULL to it as well. One other small point, how do I add NULL onto the end of a string?
0
 
LVL 7

Assisted Solution

by:leflon
leflon earned 200 total points
ID: 10860821
Dj_Fx8,
adding a NULL char to the end of a string means you put the binary 0 (not the char '0') into the proper char array positon.
easiest thing would be to initialize any string with 0 after defining it.

char sT0[256];
memset(sTo, 0x00, 256);
after this you can fill your char array with the need file strings.

leflon
0
 

Author Comment

by:Dj_Fx8
ID: 10861489
Well thats it working fine now, thanks guys for your help, I'll split the points, just as a closing comment I notice using  SHFileOperation  is considerably slower than ::MoveFile
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question