Code Monkey home page Code Monkey logo

dircpy's Introduction

dircpy

Crates.io license Docs Status

Crates.io

Test Linux Test Windows

A cross-platform library to recursively copy directories, with some convenience added.

 use dircpy::*;

 // Most basic example:
 copy_dir("src", "dest");

 // Simple builder example:
CopyBuilder::new("src", "dest")
  .run()
  .unwrap();

 // Copy recursively, only including certain files:
CopyBuilder::new("src", "dest")
  .overwrite_if_newer(true)
  .overwrite_if_size_differs(true)
  .with_include_filter(".txt")
  .with_include_filter(".csv")
  .run()
  .unwrap();
  

dircpy's People

Contributors

alecmocatta avatar fzgregor avatar nn1ks avatar woelper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dircpy's Issues

Infinite Loop

Running with v0.3.15, I'm getting an infinite loop. I was attempting to copy all files in my current directory to a sub directory only when files have a specific ending.

include_filters not working

Hi,

I'm using your crate, which perfectly meets my needs and works very well. However, I've encountered an issue with the include_filters option when using both the CopyBuilder and copy_dir_advanced methods.

Here's my code:

    fn folder_backup(settings: BackupConfig) -> anyhow::Result<()> {
        let destination_path = PathBuf::from(&settings.backup_destination).join("emergency-backup");
        info!(target: "general", "{:?}", settings.extension_type.iter().map(|ext| ".".to_owned() + ext.as_str()).collect::<Vec<_>>());
        match copy_dir_advanced(&settings.backup_source,
                                destination_path, false, true,
                                true, vec!(),
                                if settings.extension_only { settings.extension_type.iter().map(|ext| ".".to_owned() + ext.as_str()).collect() } else { vec!() } ) {
            Ok(_) => { Ok(()) }
            Err(err) => { error!("{}", err.to_string()); bail!(FileTransferError) }
        }
    }

The printed line before the copy_dir_advanced call shows:
2024-07-12 12:57:39 | INFO | path/to/file.rs:203 โ€” [".pdf", ".txt"]

I initially tried using the extension_type vector directly (in "ext" format, without the leading dot). However, I saw an example in the documentation that used the dot before the extension, so I tried that as well, but it still doesn't work.

   let destination_path = PathBuf::from(&settings.backup_destination).join("emergency-backup");
        info!(target: "general", "{:?}", settings.extension_type.iter().map(|ext| ".".to_owned() + ext.as_str()).collect::<Vec<_>>());
        let mut builder = CopyBuilder::new(&settings.backup_source, destination_path);
        if settings.extension_only {
            for ext in settings.extension_type {
                builder = builder.with_include_filter(ext.as_str());
            }
        }
        match builder.run() {
            Ok(_) => { Ok(()) }
            Err(err) => { error!("{}", err.to_string()); bail!(FileTransferError) }
        }

Am I missing something?

Thank you in advance.

UPDATE

Running this code seems not working as well:

        let mut builder = CopyBuilder::new(&settings.backup_source, destination_path)
            .with_include_filter(".txt")
            .with_include_filter(".pdf").run();

with_include_filter() adds the new filter to self.exclude_filters()

with_include_filter() adds the new filter to self.exclude_filters(), as seen here:

    pub fn with_include_filter(self, f: &str) -> CopyBuilder {
        let mut filters = self.exclude_filters.clone(); // Gets the exclude filters.
        filters.push(f.to_owned());
        CopyBuilder {
            include_filters: filters, // The include filters are then replaced with the exclude filters.
            ..self
        }
    }

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.