Solved

System Program

Posted on 1998-10-13
5
188 Views
Last Modified: 2010-04-15
I am making a program for a file server where it gets the dates from a text file then finds
all the files on the system that were made before that date and deletes them.
well I have programmed everything else, all I need to do is find out how to search the
system.  I just don't know the dos commands in c to do that, or the one's I know won't
work.  NOTE: I am programming with Borland

Thanks
0
Comment
Question by:smoothasice
  • 4
5 Comments
 
LVL 3

Accepted Solution

by:
arunm earned 100 total points
ID: 1253502
There are a few of ways  to do this:-

1) Use opendir(), readdir() and closedir()
2) Use findfirstfile(), then findnextfile() if borland C supports this (VC++ does)
3) Open a pipe and use "dir /s" from the root directory scan all the directories for files and pipe the result to another file which you can subsequently open.
 
0
 
LVL 3

Expert Comment

by:arunm
ID: 1253503
You can also use scandir() in place of 1)

 
0
 

Author Comment

by:smoothasice
ID: 1253504
How would I open a pipe?
i've tried using teh system() command but that doesn't work with borland...
0
 
LVL 3

Expert Comment

by:arunm
ID: 1253505
I think what you wnat is something like this:-

#include <stdio.h>
#include <stdlib.h>

void main( void )
{

   char   psBuffer[128];
   FILE   *filePtr;

     /* Run DIR so that it writes its output to a pipe. Open this
     pipe with read text attribute so that we can read it
     like a text file.
     */

   if( (filePtr = _popen( "dir c:\\ /s *.c", "rt" )) == NULL )
      exit( 1 );

   /* Read pipe until end of file. End of file indicates that
    * file closed its standard out (probably meaning it
    * terminated */

   while( !feof( filePtr ) )
   {
      if( fgets( psBuffer, 128, filePtr ) != NULL )
         printf( psBuffer );
   }

   /* Close pipe and print return value of fileptr. */
   printf( "\nProcess returned %d\n", _pclose( filePtr ) );
 
}
0
 
LVL 3

Expert Comment

by:arunm
ID: 1253506
This is not using rediection to a file, but directly reading the output of dir. Note the double "\\" in the pipe command, this is interpreted as "\".

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why this code doesn't work? 8 108
convert char array to number in c 5 86
What is atomic operation? 6 65
Windows Server 2012  Backup - HyperV host 18 63
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question