Solved

System Program

Posted on 1998-10-13
5
163 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
Comment Utility
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
Comment Utility
You can also use scandir() in place of 1)

 
0
 

Author Comment

by:smoothasice
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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.

743 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

10 Experts available now in Live!

Get 1:1 Help Now