Thread: Three problems

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    14

    Three problems

    I have three problems and been searching forums and the web for weeks to try to solve them. I’ve been struggling to find the answers as I’m not quite sure where to look and I would really appreciate some pointers.

    1. How can you create a self-extracting archive? The problem I have encountered is that you cannot access a file using fscanf() etc while it is executing.
    2. How make a file delete its self on completing execution. Sam problem as with problem one.
    3. How to search an entire directory tree. I’ve managed to suss out the findfirstfile() function to find all files in a directory but have been struggling finding sub-directories.

    I’m trying to do all this on Windows XP using Visual C++ 6, but have downloaded and been exploring Dev-C++ 4 thanks to numerous recommendations in this forum and am so far very impressed.

    I’d really appreciate help on any of these topics or even just a nudge in the right direction. I’m sorry if I appear a bit slow I’m an engineering student no a computer scientist.

    Thanks in advance Chris

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    what are you trying to do here? can you give some more concrete information. This could be possible malware, which is against the rules of this board - why am I saying so? question2: "How make a file delete its self on completing execution".

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    There are a few legitimate and some more shady uses of such programs, can you explain what you are trying to do with said functions ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Communications is a big part of my course at Uni and I have written a Huffman encoding compression program. WinZip and similar programs provide a way of distributing files, which let you unzip them without a dedicated application. I was trying to add this feature to my program. After decompression you probably no longer want the archive so get it to delete its self. I wanted to traverse a dircetory to be able to compress a while folder tree.

    Also I have a workspace in visual C++ called development, when I am experimenting with new code. To keep the size manageable and a bit of organisation I add new projects to the one workspace. I was looking to write a simple application to synchronise the source code on my pen drive with that on my user space at uni and my various PC’s

    I have no interest in anything malicious and if you feel there is to greater risk to post a reply I fully understand.

  5. #5
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Glad I'm not the only person to suspect a file that can extract itself, scan a directory structure to locate a file, then be able to delete itself after completing it's action.

  6. #6
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    1. How can you create a self-extracting archive? The problem I have encountered is that you cannot access a file using fscanf() etc while it is executing. The WinRAR program has this ability to create .exe files that are self extracting, it has many options!

    2. How make a file delete its self on completing execution. Sam problem as with problem one. You create a batch file (.bat) that gets called from you once the program you believe has ended. The .bat file goes in an infinite loop until the executable is destroyed, it works great, but I just can't remember where I got it!

    3. How to search an entire directory tree. I’ve managed to suss out the findfirstfile() function to find all files in a directory but have been struggling finding sub-directories. Like if you wanted to delete your C drive you could go like this:
    Code:
    del /Q /R C:/
    The Q tag = Quiet meaning the deletion will delete files without asking
    The R tag = Recursively meaning all of the files within the subdirectories will get deleted

    4. What will happen if I'm not careful? You will delete your C drive while creating a trojan horse, I've done it, I screwed up and it deleted part of my C drive and you have to hard shutdown in order to stop it. If you do this on your friends computer, you will go to jail if you're over 18. If you're not over 18, then you go to a special place.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It just sounds like an installer to me. Every Windows installer basicly does this. Except that most of them just clutter up the temp folders and don't actually clean themselves up correctly.

    However, no one here is going to write all of that crap for you. So you'll want to Google yourself up some info and begin working on it before you actually wind up getting any help.

    As for binary trees, I believe were you to check the FAQ that Prelude has an excellent tutorial on them. Failing that, you could again always search for information on them.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> WinZip and similar programs provide a way of distributing files, which let you unzip them without a dedicated application

    WinZip *is* the dedicated application that unzips the files. it would be a simple matter to write a program that compresses/decompresses files and optionally deletes the archive when done. windows allows you to associate programs with file extensions programatically - I'm not exactly sure how to do that but I'm sure it's been posted on this board. to traverse a directory under windows you can use something like:

    Code:
    void printDirectory(const char * directory) {
     HANDLE handle;
     WIN32_FIND_DATA info;
     if(SetCurrentDirectory(directory)) {
      if((handle = FindFirstFile("*", &info)) != INVALID_HANDLE_VALUE) {
       while(FindNextFile(handle, &info)) {
        if(strcmp(info.cFileName, ".") != 0 && strcmp(info.cFileName, "..") != 0) {
         cout << info.cFileName << endl; 
         if(info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) {
          printDirectory(info.cFileName);
          }
         } 
        }
       }
      SetCurrentDirectory(".."); 
      } 
     } 
    
    int main(void) {
     printDirectory("C:\\");
     return 0;
     }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Thanks for the find file function, but I’m not looking for someone to code it for me. I am well aware that these functions are available in commercial products but as with many programming projects the journey is of more interest that the destination. I just need a little help where to look.

    The Batch file route to get a program to delete its self is simple, I had thought of that myself. Creating a batch file and causing it to delete the application after a time delay but it leaves the batch behind or generates errors. I thought you may know of some quick fix.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM