I am trying to remove files from a couple of directories after a process completes. Below is what I have so far, but the command does not run and cygwin closes too fast to read the error. Also, is it possible to have the printf be displayed until the files are removed then printf in italics is displayed and the program exits? Thank you :).
remove() {
printf "\n\n"
printf "Removing old files, please wait ";
# annovar directory
my $filename = qw[ 'C:\Users\cmccabe\Desktop\annovar\out_position.txt', 'C:\Users\cmccabe\Desktop\annovar\out_parse.txt' ];
unlink $filename or die "Couldn't unlink($filename) : ($!)($^E)";
# python directory
my $filename = qw[ 'C:/Users/cmccabe/Desktop/Python27/${id}.txt', 'C:/Users/cmccabe/Desktop/Python27/out_name.txt' ];
unlink $filename or die "Couldn't unlink($filename) : ($!)($^E)";
printf "\n Old files removed, Goodbye! \n\n"; sleep 2 && exit
}
I am invoking the sub-routine as part of a bash menu. Basically, the user is prompted with a Yes/No selection and a No response leads to the sub-routine: Is there a better way to remove files after a script completes?
I modified it a bit and it runs now but the files still remain in the directory and are not removed. $id.txt is a variable in the python directory that represents the id that the user types in. Thank you :).
remove() {
printf "\n\n"
printf "Removing old files, please wait ";
# annovar directory
my $filename = qw[ 'C:\Users\cmccabe\Desktop\annovar\out_position.txt' ];
my $filename = qw[ 'C:\Users\cmccabe\Desktop\annovar\out_parse.txt' ];
unlink $filename or die "Couldn't unlink($filename) : ($!)($^E)";
# python directory
cd cd 'C:'
my $filename = qw[ C:/Users/cmccabe/Desktop/Python27/$id.txt ];
my $filename = qw [ C:/Users/cmccabe/Desktop/Python27/out_name.txt ];
unlink $filename or die "Couldn't unlink($filename) : ($!)($^E)";
printf "\n Old files removed, Goodbye! \n\n"; sleep 2 && exit
}
Remembering well your other threads in which you built shell scripts with only a few python commands, I'd second balajesuri"s assumption that you mix shell/perl/python commands. Why don't you just use the rm command in shell?