matklad / xshell

Apache License 2.0
675 stars 28 forks source link

Remove all files inside a directory #67

Closed azzamsa closed 1 year ago

azzamsa commented 1 year ago

Hi.

I am having a hard time removing all files inside a directory. With bash, I can use rm -rf /home/user/.tmp/* (note asterisk). With xshell, it doesn't work.

    cmd!(sh, "rm -rf /home/user/.tmp/*").run()?;  // ⚠️, doesn't work
    sh.remove_path("/home/user/.tmp/*")?;  // ⚠️, doesn't work

My only option is to remove the .tmp directory and recreate it again. Is there any way to tell xshell to remove the content of a directory, similar to .tmp/*, leaving the parent directory (.tmp) intact?

Thanks a lot for xshell :heart:

azzamsa commented 1 year ago
    let paths = fs::read_dir("/home/user/.tmp"))?;
    for path in paths {
        sh.remove_path(path?.path())?;
    }

Solved :tada:

matklad commented 1 year ago

FWIW, I think it would make sense for xshell to support globbing, but yeah, that’s not impemented