Solved

System Program

Posted on 1998-10-13
5
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

615 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