#! /usr/bin/perl -W # this program copy all files in a directory # and deplace them in a new directory if he doesn't exist # the program creat him... use strict ; my($targetDirFull,$targetDir, $origDirFull,$origDir,$bit, @allThings,$i,$file,@fileIn); $targetDir = 'multimedia'; $targetDirFull = 'C:\target\' ; $origDirFull = 'C:\Program Files\origin\' ; #------------------------------------- #verification that "Target" exist- #------------------------------------- unless( chdir('C:\\') ) { print "Error 1..\n" ;} else { chdir('C:\\'); } unless (-e $targetDir) { print "creating directory \"Target\"...\n"; mkdir('Target',0777); } ################################################################# ## openning "origine";take each file and write them in "target" # ################################################################# opendir(ORIG,$origDirFull) or die("the directory is unavaible !\n") ; unless(readdir(ORIG)) { print "Error 2" ; } else { print "open $origDirFull ... [OK]\n"; @allThings = readdir(ORIG); if ($allThings[0] eq "") { print "the directory is empty ..normal ?\n"; } else { print "there's some file in this directory..\nI deplace them\n"; while($allThings[0] ne "") { $file = pop(@allThings) ; open(INPUT,$file) or die ("Error 3\n"); @fileIn = ; close(INPUT); opendir(TARGET,$targetDir."\"") or die ("this computer is anormaly create..\n"); open(OUTPUT,">".$file) or die ("Error 4\n"); foreach $bit (@fileIn) { print OUTPUT $bit ; } close(OUTPUT); closedir(TARGET); } } }