how to write a program that will behave much the same as the DIR command in DOS

This is a discussion on how to write a program that will behave much the same as the DIR command in DOS within the C Programming forums, part of the General Programming Boards category; Assume the help page of the dir command looks like this. DIR [-a[attributes]] [-b] [-o[[:]sortorder]] [-p] [-q] [-t[[:]timefield]] [-w] [path] ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    1

    how to write a program that will behave much the same as the DIR command in DOS

    Assume the help page of the dir command looks like this.

    DIR [-a[attributes]] [-b] [-o[[:]sortorder]] [-p] [-q] [-t[[:]timefield]] [-w] [path] [filename/dirname]

    [path] [filename] Specify directory, and-or file to list
    -a Display files with specific attributes
    [attributes] d directories r read only files h hidden files
    -b Use bare format (no heading information)
    -o List by files in sorted order.
    [sortorder] n by name (alphabetic) s by size g group directories d by date-time (oldest first)
    -p Pause after each successful (24 lines) of information
    -q Display the owner of the file
    -s Displays files in specific directory and all sub directories
    -t Controls which time field is displayed
    [time field] a last time accessed w last written
    -w Use wide list formatAssume the help page of the dir command looks like this.

    DIR [-a[attributes]] [-b] [-o[[:]sortorder]] [-p] [-q] [-t[[:]timefield]] [-w] [path] [filename/dirname]

    [path] [filename] Specify directory, and-or file to list
    -a Display files with specific attributes
    [attributes] d directories r read only files h hidden files
    -b Use bare format (no heading information)
    -o List by files in sorted order.
    [sortorder] n by name (alphabetic) s by size g group directories d by date-time (oldest first)
    -p Pause after each successful (24 lines) of information
    -q Display the owner of the file
    -s Displays files in specific directory and all sub directories
    -t Controls which time field is displayed
    [time field] a last time accessed w last written
    -w Use wide list format

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,323
    The trick is to use something called "Command Line Arguments"

    Tutorial -> Command Line Arguments in C - Cprogramming.com
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    289

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,053
    I would use opendir and readdir from dirent.h. It works on UNIX as well as Windows with MinGW. You might be interested in this thread which shows an example:

    How can I get a list of files in a directory using C or C++? - Stack Overflow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-27-2010, 11:42 AM
  2. Own Shell: Displaying prompt and write a command
    By xyphen in forum C Programming
    Replies: 4
    Last Post: 12-08-2009, 03:21 PM
  3. Write in many command prompts
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2004, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21