Create dir dos command in c programming language

C program or code to create DOS command DIR

Step 1: Write following code.

#include <stdio.h>

#include <dos.h>

int main(int count,char *argv[]){

struct find_t q ;

    int a;



    a = _dos_findfirst(argv[1],1,&q);


         while (!a){

             printf("  %s\n",;

             a = _dos_findnext(&q);




         printf("File not found");


    return 0;

Step 2: Save the as open.c (You can give any name)
Step 3: Compile and execute the file.
Step 4: Write click on My computer of Window XP operating system and select properties.
Step 5: Select Advanced -> Environment Variables
Step 6: You will find following window:

Click on new button (Button inside the red box)

Step 7: Write following:
Variable name: path
Variable value: c:\tc\bin\open.c  (the path where you have saved)

Step 8: Open command prompt and write list and press enter button.

C tutorial home.

If you have any suggestions on above create dir command in c, please share us.


K K said...

hi.. this is goutam ..
i need the code for copy cmd.. if possible need the explanation...

johnwick said...

Thankyou for this blog its really interesting and informative, but there is some errors
Which need to be recorrect by owner. See i also have some good blogs related to
Technical services, you can check on my website.

Avast Login
bullguard support number