validate_directory_structure

Crates.iovalidate_directory_structure
lib.rsvalidate_directory_structure
version
sourcesrc
created_at2025-03-26 04:00:17.110462+00
updated_at2025-03-31 16:41:57.070981+00
descriptionA powerful tool to validate directory(Files and folders) structures.
homepage
repositoryhttps://gitlab.com/public-sources1/validate_directory_structure
max_upload_size
id1606130
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
SonickSeven (sonickseven)

documentation

https://docs.rs/crate/validate_directory_structure/latest

README

Index

Directory Structure Validator

A tool to validate directory structures against a JSON schema. Checks for required folders and files according to the specified configuration.

Features

  • Validates nested folder structures

  • Checks for required/optional files

  • Supports file extensions validation

  • Detailed error reporting

Example JSON structure

{
  "name": "TEST",
  "description": "Structure of folders, folders required and files required",
  "folders": [
    {
      "required": true,
      "names": ["forest", "trees field"],
      "files": [
        {
          "required": true,
          "names": ["mountain", "hill"]
        }
      ],
      "folders": [
        {
          "names": ["sub_forest", "sub forest"],
          "required": true,
          "files": [
            {
              "names": ["file_sub_forest", "sub forest"],
              "required": true
            },
            {
              "names": ["file_optinal"],
              "required": false
            }
          ]
        }
      ]
    },
    {
      "required": false,
      "names": ["rivers"],
      "files": [
        {
          "required": true,
          "names": ["aaaa", "bbbbb"]
        }
      ]
    }
  ]
}

Significant typing

#[derive(Debug, Serialize)]
pub enum ItemType {
  File,
  Folder,
}

#[derive(Debug, Serialize)]
pub enum AlertType {
  Warning, // --> Works only for property "required" false in JSON
  MissingItem,
  ExtraItem,
  ErrorReadingFile,
}

#[derive(Debug, Serialize)]
pub struct AlertFileStructure {
  pub path: String,
  pub item_type: ItemType,
  pub alert_type: AlertType,
}

Usage:

# Cargo.toml

[dependencies]
validate_directory_structure = "0.2.3"
use validate_directory_structure::ValidateDirTree;

let validate_structure = ValidateDirTree {
    required_extensions: vec!["html", "css", "js"], // extensions of files mandatory
    valid_extensions: vec!["ts", "tsx"], // These extensions aren't mandatory on folder
  };

let results = validate_structure.validate_structure("/your/folder/path", YOUR_JSON_STRUCTUEE);

println!("these are the results: {:?}", results);

Directory tree on my my_project_example

/ my_project_example
β”œβ”€β”€ trees field                   πŸ—Ή
β”‚   β”œβ”€β”€ mountain.html             πŸ—Ή
β”‚   β”œβ”€β”€ mountain.js               πŸ—Ή
β”‚   β”œβ”€β”€ mountain.css              πŸ—Ή
β”‚   β”œβ”€β”€ main.js                   πŸ—· // no defined on JSON structure
β”‚   └── sub_forest                πŸ—Ή
β”‚       β”œβ”€β”€ file_optinal.html     πŸ—Ή
β”‚       β”œβ”€β”€ file_optinal.js       πŸ—Ή
β”‚       β”œβ”€β”€ file_optinal.css      πŸ—Ή
β”‚       └── file_optinal.lock     πŸ—· // no defined on JSON structure
β”‚       └── file_optinal.ts       πŸ—Ή
└── ocean                         πŸ—· // no defined on JSON structure
    β”œβ”€β”€ pacific.html              πŸ—· // only show message in parent folder
    └── pacific.js                πŸ—· // only show message in parent folder

Sample Output Vec<AlertFileStructure>

List of errors

  • Error - > File "/trees field/main.js" is a ExtraFile because wasn't defined on JSON
  • Error - > File "/trees field/sub_forest/file_sub_forest.js" is a MissingFile because was defined on JSON
  • Error - > File "/trees field/sub_forest/file_sub_forest.css" is a MissingFile because was defined on JSON
  • Error - > File "/trees field/sub_forest/file_sub_forest.html" is a MissingFile because was defined on JSON
  • Error - > File "/trees field/sub_forest/file_optinal.lock" is a ExtraFile because wasn's defined on JSON
  • Warning - > Folder "/rivers" because it isn't mandatory however is a ExtraFile
  • Error - > Folder "/ocean" is a ExtraFile because that folder wasn't defined on JSON
Commit count: 0

cargo fmt