Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Move a File

Posted on 2004-04-19
8
Medium Priority
?
744 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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