I'm struggling with the code for this. I've tried varoius things. The closest I've got isprompt user to enter a directory name Check if directory name exists If it does prompt user again and ask if the contents of the dir can be + overwritten. If it can continue with rest of program otherwise loop round again asking the same questions and doing the sam +e checks again . This bit may need to be run several times depending +on whether the user enters an existing dir or not.
It doesn't work. I'm fairly new to Perl and I suspect the code above reflects that ! This is on Unix (Solaris) . Any help is welcomeuse warnings; use strict; use Term::Prompt; use File::Find; no warnings 'File::Find'; sub Wanted; my ($dirname,$ans); $basedir="/dmp/backup"; $dirname = prompt('e', 'Enter a dir name', 'e.g. regression-EO +DDAY1', '','[A-Za-z0-9_-]+' ); # Check whether the dir already exists if find(\&Wanted, $basedir) { $ans = prompt('y', 'That dir already exists, do you wi +sh to overwrite the existing contents ?','[y/n]','n'); if ($ans = 1) { $dirname = prompt('e', 'Enter a dir name', 'e. +g. regression-EODDAY1', '','[A-Za-z0-9_-]+' ); } if find(\&Wanted, $basedir) { $ans = prompt('y', 'That dir already exists, d +o you wish to overwrite the existing contents ?','[y/n]','n'); if ($ans = 1) { $dirname = prompt('e', 'Enter a dir na +me', 'e.g. regression-EODDAY1', '','[A-Za-z0-9_-]+' ); } } } sub Wanted { my $dir = $File::Find::name; print if /$dirname/ ; return; }
In reply to A looping question by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |