clear-script/clear-hidden-dirs.v

64 lines
1.4 KiB
V

module main
import os
const start_path := os.getwd()
const y_all_patterns := os.getenv('Y_ALL_PATTERNS')
const patterns = ['.node_module', '.node_modules', '.wine', '.local', '.config', '.fonts', '.cache', '.cargo', '.npm', '.npm-global', '.npmrc', '.go']
struct Rtime {
mut:
counter u64
}
fn main() {
println('starting out in ${start_path}')
mut rtime := Rtime{
counter: 0
}
os.walk_with_context(start_path, &rtime, check_ent)
}
fn check_ent(mut rtime Rtime, fpath string) {
rtime.counter += 1
println('processing entity ${rtime.counter}: ${fpath}')
split_fpath := fpath.split('/')
c := split_fpath[split_fpath.len -1]
s := os.stat(fpath) or {
panic(err)
}
for p in patterns {
if p == c {
println('Do you want to remove ${fpath}? y/n')
a := os.get_line()
if a == 'y' || y_all_patterns == 'true' {
println('deleting ${fpath}')
op := os.execute('rm -rf ${fpath}')
if op.exit_code == 0 {
println('${fpath} was successfully removed')
} else {
println('could not remove ${fpath}')
}
} else {
continue
}
}
}
if s.size > 400000000 {
println('${fpath} is ${s.size/1000000}MB')
println('Do you want to remove ${fpath}? y/n')
a := os.get_line()
if a == 'y' {
op := os.execute('rm -rf ${fpath}')
if op.exit_code == 0 {
println('${fpath} was successfully removed')
} else {
println('could not remove ${fpath}')
}
}
}
}