• Advertisement
Sign in to follow this  

Remove File

This topic is 4561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, how can i make my program so that if you just type the name+extention that it will automaticly delete. Cause it works now fine but only in the map were the program is. so if i open my program i can only delete files in the same map as where my program is. I was wandering if you guys know how i can make something that will search files trough the whole computer? this is my code:
// FileRemover v1.00
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  cout <<  ("Current date and time are: %s", asctime (timeinfo));

    cout << "                  **********************************************" << endl;
    cout << "                  *        **FileRemover**  by jordi_0071      *" << endl;
    cout << "                  **********************************************" << endl;
   char pathbuffer[_MAX_PATH];
   char searchfile[265];
   char envvar[] = "PATH";

cout << "Enter the file plus extention (example: .exe, .txt): ";

cin >> searchfile;

   /* Search for file in PATH environment variable: */
   _searchenv( searchfile, envvar, pathbuffer );
   if( *pathbuffer != '\0' )
      cout << ("Path for %s: %s\n", searchfile, pathbuffer);
      printf( "%s not found\n", searchfile );


    return 0;

Share this post

Link to post
Share on other sites
I'm assuming that by "map" you mean "path". Take a look at Boost::Filesystem, which povides portable facilities to query and manipulate paths, files, and directories.
Specifically, examine this sample program which iterates through a given path. Although the program just lists the files, it can be easily modified to delete files that match a certain pattern, as you describe.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement