Thread: File help

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    4

    File help

    Hi all. First time poster here, Im going to try my best in explaining on what i need. I have a program that downloads an update to the package. I havnt gotten so good that i can update the file with out stopping or closing it but this is the only solution i could come up with. In order for the new program to work the old one has to download it. Then open it. I used ShellExecute() to open the new program. Thats not the problem though. Well now that i have the new program in the install folder, i need to kick the old one. So what im trying to do is get it to delete any files that opened it. I'll make a brief description.

    old-file.exe opens new-file.exe

    new-file.exe starts up and deletes old-file.exe
    I cant make it any simple than that. I thought by using argv that would be a start in figuring it out but i dont know how. Any suggestions? Thanx in advance!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Seems like a plausible solution. When you say "any suggestions", what exactly are you fishing for? Alternative solutions, code implementation, or something else.

    If you want alternative solutions, it would be useful to know:
    1. What other concepts have you rejected?
    2. What benefits are you looking for in an alternative solution?

    It's also useful if you indicate which operating system(s) this is for - the solution for Linux may be different than the Windows one.

    As an overall concept, I don't think there is much you can do that is majorly different - you do need to download the new application, and you do need to start the new one and "finish off" the old applicatin. There is not much else we can say on that matter. There may be slight variations in EXACTLY how you go about doing that - but that is about it.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Quote Originally Posted by matsp View Post
    It's also useful if you indicate which operating system(s) this is for - the solution for Linux may be different than the Windows one.
    Is this a nix programming thread? Sorry i didnt see the Windows one. But if you can help or offer any advice i'd appreciate it. My problem consist of the ShellExecute() WinAPI. I have a program that needs to be updated. So in order for the update to be accomplished is i need the old file to download the update and the new file to delete the old one because its no longer needed. I could always do system("del old-file.exe"); but i would have to specify the file name every time i do, Which is not something i'd like to do. So im trying to pass the argv[0] through ShellExecute so it can pass the path/filename to the new file. I hope im being clear as to what im trying, if not tell me what you dont understand and i'll try my best to explain thoroughly. Thanx in advance!

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Is this a nix programming thread?
    No, it's for general programming. But there is no platform-agnostic solution to your problem, so the information would be good.

    Of course, the ShellExecute() and the .exe file ending are pretty good giveaways.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by dellthinker View Post
    Hi all. First time poster here, Im going to try my best in explaining on what i need. I have a program that downloads an update to the package. I havnt gotten so good that i can update the file with out stopping or closing it but this is the only solution i could come up with. In order for the new program to work the old one has to download it. Then open it. I used ShellExecute() to open the new program. Thats not the problem though. Well now that i have the new program in the install folder, i need to kick the old one. So what im trying to do is get it to delete any files that opened it. I'll make a brief description.



    I cant make it any simple than that. I thought by using argv that would be a start in figuring it out but i dont know how. Any suggestions? Thanx in advance!
    hmm.. I had a similar prob to do..
    if you are not using some other program/daemon/installers..
    you can do it simply by a batchfile..
    generate a bathcfile before quit.. and generate it on the fly by your updater..
    dont hardcode it..
    then launch the batchfile that inturn launches your new app..
    batchfile can del itself.. so everything is fine..
    C's Motto: who cares what it means? I just compile it!!

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by dellthinker View Post
    I could always do system("del old-file.exe");
    http://cppreference.com/stdio/remove.html

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Thanx for your replies but they really didnt do me much good.

    gibsosmat: I dont need a batch file because my project consist of trying this in C++. Thanx but no cigar.

    robwhit: remove()/DeleteFile() both works fine. Now how can i get them to delete a file that opened it?

    CornedBee: ...... huh?

    If anyone else has a solution please dont hesitate to let me know. Thanx in advance!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM