Implement Following C Mkdir Creates Empty Subdirectory Current Directory Ls List Contents Q37130411

How to implement the following in c++

– mkdir Creates an empty subdirectory in the currentdirectory.

– ls List the contents of the current directory. Directoriesshould have a ‘/’ suffix such as ‘myDir/’. Files do not have asuffix.

– cd Change to specified directory. The directory must be asubdirectory in the current directory. (No paths or “..” areallowed.)

-cat Display the contents of the file to the screen. Print anewline when completed.


Answer


sample.cpp:

#include<stdio.h>
#include <cstdlib>
#include<iostream>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
int main()
{
extern int errno;
if (mkdir(“new_folder”, 0777) == -1)
        cout << “Error :Creating folder, folder already exists” <<endl;
    else
        cout << “Directorycreated”<<endl;
cout<<endl<<endl<<endl;
cout<<“Contents of current directory”<<endl;
system(“ls -p”);
cout<<endl<<endl<<endl;
cout<<“Printing contents

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.