C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2003, 07:40 AM
EzehM EzehM is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: London
Posts: 2 EzehM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Help ! MoveFileEx Problem

I have a piece of code that renames a file from A.ACK.tmp to A.ACK in the same directory (C:\abc). Meanwhile there is another process that polls C:\abc, looking for files with a .ACK extension. Once it sees such a file, it moves it to folder D:\ABC.

To rename the file I do the following

if ( !::MoveFileEx(tmpRnFile, RenamedFileName,
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) )
{
LogEvent(EVMSG_SENT_FAILED, tmpRnFile, RenamedFileName, GetLastErrorString() );
return EVMSG_SENT_FAILED;
}

Where tmpRnFile = C:\abc\A.ACK.tmp and RenamedFileName = c:\abc\A.ACK

The problem I have is that MoveFileEx returns a nonzero value - GetLastError returns 0x2: The system cannot find the file specified.

Please can anyone help? How does a move process work in NT, and can another process move or delete a file during the rename process?

What other rename method can I use to ensure that I dont get this problem.

Thanks
Milton

Reply With Quote
  #2  
Old June 9th, 2003, 03:00 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,139 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 17 m
Reputation Power: 1974
Just a stupid question that might solve the problem:
When you assign the file name, are you using single or double back-slashes? I.e., you say that tmpRnFile = C:\abc\A.ACK.tmp and RenamedFileName = c:\abc\A.ACK.
But did you actually write them that way or did you write them as "C:\\abc\\A.ACK.tmp" and "c:\\abc\\A.ACK"?.

In C/C++, the back-slash is used in character and string literals as an "escape" with which to represent special characters, like the new-line ('\n') or the NUL ('\0') or a quote mark embedded within the string (eg, "This is an example of \"embedded\" quote marks."). Therefore, to represent an actual backslash in a string literal, you need to enter it twice as I had done in my question above.

Hope that's all it was. If it's any consolation, I've been bitten by the same thing before.

Reply With Quote
  #3  
Old June 10th, 2003, 01:26 AM
EzehM EzehM is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: London
Posts: 2 EzehM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry, my mistake, I actually used "C:\\abc\\A.ACK.tmp" and "c:\\abc\\A.ACK"?.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help ! MoveFileEx Problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap