use File::Path qw(make_path remove_tree);
my $root_dir = './example_directoy';
my $lang_dir = 'perl';
my $dirpath = join('/', $root_dir, $lang_dir);
unless(-d $dirpath){
make_path($dirpath);
}
if(-d $dirpath) {
print "Succeeded in creation of ".$dirpath."\n";
if($root_dir=~ m![a-zA-Z\d_\-]!){
remove_tree($root_dir);
}
if(-d $root_dir) {
die("Failed to remove ".$root_dir)
}
else{
print "Succeeded in removal of ".$dirpath."\n";
}
}
else{
print "Failed to mkdir -p ".$dirpath."\n";
}
Python
import os
import re
import shutil
root_dir = './example_directoy'
lang_dir = 'python'
dirpath = '/'.join([root_dir, lang_dir])
if not os.path.isdir(dirpath):
os.makedirs(dirpath)
if os.path.isdir(dirpath):
print("Succeeded in creation of " + dirpath)
if re.search(r"[a-zA-Z\d_\-]", root_dir):
shutil.rmtree(root_dir)
if not os.path.isdir(root_dir):
print("Succeeded in removal of " + root_dir)
Ruby
require 'fileutils'
root_dir = './example_directoy'
lang_dir = 'ruby'
dirpath = [root_dir, lang_dir].join("/")
FileUtils.mkdir_p(dirpath)
if Dir.exist?(dirpath)
print("Succeeded in creation of " + dirpath + "\n")
if root_dir.match("[a-zA-Z\d_\-]")
FileUtils.remove_dir(root_dir)
if !Dir.exist?(root_dir)
print("Succeeded in removal of " + root_dir + "\n")
end
end
end
Shell
ROOTDIR='./example_directoy';
LANGDIR='python';
DIRPATH=$ROOTDIR'/'$LANGDIR;
mkdir -p $DIRPATH;
if [ -d $DIRPATH ]
then
echo "Succeeded in creation of ".$DIRPATH;
fi
if [[ $DIRPATH =~ [a-zA-Z\d_\-] ]]
then
rm -r $ROOTDIR;
fi
if [ ! -d $ROOTDIR ]
then
echo "Succeeded in removal of ".$ROOTDIR;
else
echo "Failed in removal of ".$ROOTDIR;
fi