Solved

System Program

Posted on 1998-10-13
5
175 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 how to use strings and some functions related to them in the C programming language.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now