Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Move a File

Posted on 2004-04-19
8
Medium Priority
?
745 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
  • 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 800 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
Independent Software Vendors: 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 800 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

916 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