Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System Program

Posted on 1998-10-13
5
Medium Priority
?
200 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

705 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