file help
-
Hi all. My goal here is to copy the currently used file. Then start the new file and delete the old one. An update sequence if you will. My code:
#include #include using namespace std; int main(int argc, char *argv[]) { char *file="program.exe"; char *currentfile = argv[0]; CopyFile(currentfile, file, FALSE); if(file == currentfile){ Sleep(8000); DeleteFile(argv[1]); } else{ ShellExecute(0,"open", file, argv[0], 0, SW_SHOW); exit(1); } return 0; }
Im stumped trying to figure this out. Any suggestions will be accepted (as long as their helpful =P). I think its trying to delete itself, which is 'not' what im trying to do. So if anyone can help me figure out what im doing wrong i'd be very greatful. Thanx in advance! -
Hi all. My goal here is to copy the currently used file. Then start the new file and delete the old one. An update sequence if you will. My code:
#include #include using namespace std; int main(int argc, char *argv[]) { char *file="program.exe"; char *currentfile = argv[0]; CopyFile(currentfile, file, FALSE); if(file == currentfile){ Sleep(8000); DeleteFile(argv[1]); } else{ ShellExecute(0,"open", file, argv[0], 0, SW_SHOW); exit(1); } return 0; }
Im stumped trying to figure this out. Any suggestions will be accepted (as long as their helpful =P). I think its trying to delete itself, which is 'not' what im trying to do. So if anyone can help me figure out what im doing wrong i'd be very greatful. Thanx in advance!I can't figure out what you are really trying to do. First thing I've noticed is that. you are mainly dealing with a hardcoded file name "program.exe" and passed argument value which is in argv[0]. But you are trying to delete a file which is in argv[1]. I doubt you are really intended to deal with that parameter.
-Sarath_._ "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts, An Article - Understanding Statepattern
-
Hi all. My goal here is to copy the currently used file. Then start the new file and delete the old one. An update sequence if you will. My code:
#include #include using namespace std; int main(int argc, char *argv[]) { char *file="program.exe"; char *currentfile = argv[0]; CopyFile(currentfile, file, FALSE); if(file == currentfile){ Sleep(8000); DeleteFile(argv[1]); } else{ ShellExecute(0,"open", file, argv[0], 0, SW_SHOW); exit(1); } return 0; }
Im stumped trying to figure this out. Any suggestions will be accepted (as long as their helpful =P). I think its trying to delete itself, which is 'not' what im trying to do. So if anyone can help me figure out what im doing wrong i'd be very greatful. Thanx in advance!dellthinker wrote:
if(file == currentfile){
this will never be true, these two pointers are always different.
dellthinker wrote:
Sleep(8000);
I like those out-of-the-blue numbers. Should I increase or decrease them when switching to a faster CPU or another Windows version? :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
I can't figure out what you are really trying to do. First thing I've noticed is that. you are mainly dealing with a hardcoded file name "program.exe" and passed argument value which is in argv[0]. But you are trying to delete a file which is in argv[1]. I doubt you are really intended to deal with that parameter.
-Sarath_._ "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts, An Article - Understanding Statepattern
Sarath. wrote:
I can't figure out what you are really trying to do.
"My goal here is to copy the currently used file. Then start the new file and delete the old one." I've already said that, i _know_ the code is wrong. Im asking for help in trying to fix it.
-
Sarath. wrote:
I can't figure out what you are really trying to do.
"My goal here is to copy the currently used file. Then start the new file and delete the old one." I've already said that, i _know_ the code is wrong. Im asking for help in trying to fix it.
Sorry if I misinterpreted your question. Seems someone else already answered your question. In addition you will have to use strcmp or any other string comparison routine to compare the strings...
-Sarath_._ "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts, An Article - Understanding Statepattern
-
Hi all. My goal here is to copy the currently used file. Then start the new file and delete the old one. An update sequence if you will. My code:
#include #include using namespace std; int main(int argc, char *argv[]) { char *file="program.exe"; char *currentfile = argv[0]; CopyFile(currentfile, file, FALSE); if(file == currentfile){ Sleep(8000); DeleteFile(argv[1]); } else{ ShellExecute(0,"open", file, argv[0], 0, SW_SHOW); exit(1); } return 0; }
Im stumped trying to figure this out. Any suggestions will be accepted (as long as their helpful =P). I think its trying to delete itself, which is 'not' what im trying to do. So if anyone can help me figure out what im doing wrong i'd be very greatful. Thanx in advance!char *file="program.exe"; char *currentfile = argv[0]; if(file == currentfile){ ...
In this case you're comparing to pointers -- not 2 strings. You must use a string comparison function to do it... strcmp?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)
-
char *file="program.exe"; char *currentfile = argv[0]; if(file == currentfile){ ...
In this case you're comparing to pointers -- not 2 strings. You must use a string comparison function to do it... strcmp?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)
probably want it case-insensitive...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
dellthinker wrote:
if(file == currentfile){
this will never be true, these two pointers are always different.
dellthinker wrote:
Sleep(8000);
I like those out-of-the-blue numbers. Should I increase or decrease them when switching to a faster CPU or another Windows version? :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
Luc Pattyn wrote:
I like those out-of-the-blue numbers. Should I increase or decrease them when switching to a faster CPU or another Windows version?
:laugh: 5 for that.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.