Skip to content

Directory Structure is a go library for reading and transversing your local filesystem.

License

Notifications You must be signed in to change notification settings

auroq/directory-structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Directory Structure

Directory Structure is a go library for reading and transversing your local filesystem. Currently it consists of one package: structure

NOTE: This library does not do any modification to the actual local filesystem.

Parts of Structure

Structure provides three structs: Directory, File, and Descendants

Directory is the core of structure. It is a tree where each node contains the following:

  • Name(): the name of the directory
  • Path(): the path to the directory excluding Name()
  • FullPath(): the full path to the directory including Name()
  • Files(): pointers to the files contained in the directory
  • SubDirectories(): pointers to Directories in this Directory

File represents a single file. It consists of the following:

  • Name(): the name of the directory
  • Path(): the path to the directory excluding Name()
  • FullPath(): the full path to the directory including Name()

Descendants is used for convenience when getting all the Files and Directories that are descendants of a Directory. It consists of the following:

  • Directories: the Directories that are Descendants of a Directory
  • Files: the Files that are Descendants of a Directory

Functionality of Structure

Directory Tree Creation

There are two main ways to create a Directory tree

  1. Call NewDirectory(): This create a new directory with no files or subdirectories.
  2. Call GetDirectoryStructure(): This walks your local filesystem at the path provided and generates a full Directory tree that matches the given directory.

Adding Items to a Directory Tree

Directories and Files can be added to a directory tree by calling either directory.AddDirectory() or directory.AddFile() on any directory in the tree that is a ancestor of the new item. Either method takes the full path to the new item, and will create directories as needed between the ancestor Directory and the new item.

Searching a Directory or Directory Tree

Direct Child

A Directory or File that is a direct child of the current directory can be found by calling directory.Directory() or directory.File() on the current directory and passing it the name of the Directory of File.

Descendant By Path

Descendants of a Directory can be found using the Descendant's full path by calling either directory.GetDirectory() or directory.GetFile()

Descendant By Name

A depth first search by name can be done by calling directory.FindDirectoryDepth() or directory.FindFileDepth()

A breadth first search by name can be done by calling directory.FindDirectoryBreadth() or directory.FindFileBreadth()

About

Directory Structure is a go library for reading and transversing your local filesystem.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages