Link to home
Start Free TrialLog in
Avatar of Dj_Fx8
Dj_Fx8

asked on

Move a File

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
Avatar of leflon
leflon
Flag of Germany image

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
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dj_Fx8,
yepp, CopyFile() modifies the date the same way MoveFile did, sorry.
AlexFM's comment sounds good (will try it now too :) )

leflon
Avatar of Dj_Fx8
Dj_Fx8

ASKER

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;

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.

Avatar of Dj_Fx8

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dj_Fx8

ASKER

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