Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. file help

file help

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dellthinker
    wrote on last edited by
    #1

    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!

    S L P 3 Replies Last reply
    0
    • D dellthinker

      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!

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • D dellthinker

        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!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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


        R 1 Reply Last reply
        0
        • S Sarath C

          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

          D Offline
          D Offline
          dellthinker
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • D dellthinker

            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.

            S Offline
            S Offline
            Sarath C
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • D dellthinker

              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!

              P Offline
              P Offline
              Peter Weyzen
              wrote on last edited by
              #6

              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)

              L 1 Reply Last reply
              0
              • P Peter Weyzen

                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)

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                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


                1 Reply Last reply
                0
                • L Luc Pattyn

                  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


                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  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Ã<-·´¯`·.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups