Git Product home page Git Product logo

traversing-directories-in-c's Introduction

Traversing Directories in C

Author: Jack Robbins

This project contains one C program, count_lines.c, that takes in a path to a directory as input, and then opens that directory, if possible, and recursively, in a depth-first search manner, goes through every sub-directory of that directory. Simply to show functionality and demonstrate the potential usefulness of this kind of directory traversal, this program also counts the number of lines in any and all text(.txt extension) files under said directory and any of its subdirectories.

Running this program

For convenience, a runner script run.sh has been provided that compiles the program, takes in user input, and runs the program all at once. An example of how to use it is below.

Note

After downloading run.sh, be sure to grant executable permissions by running chmod +x run.sh

Example: Counting all of the lines in all .txt files under your Documents folder on a Linux system

example@bash:~$ ./run.sh count_lines.c
If your program requires input, enter it here: /home/<your_username>/Documents

So long as the pathname provided to the program is a valid path to a directory, the program will attempt to traverse said directory.

Warning

Since this script provides a recursive depth-first traversal solution, attempting to run the script on the root directory: / or any other large directories that have subdirectories that each have numerous subdirectories(etc. etc.) will cause a stack overflow, leading to a segmentation fault error. This program is not intended for searching through an entire file system.

traversing-directories-in-c's People

Contributors

jackr276 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.