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
Solved

Move a File

Posted on 2004-04-19
8
739 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 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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