Hello Monks, I am struggling with a code. It is a very simple one, yet I simply CANNOT see where it fails exactly. Here is what I am trying to accomplish: Open a directory, 'scan' the files inside and get their extension (txt, html, pdf, you name it), create subfolders with these extensions, and then copy the files to these subfolders. The code seems to work because I manage to copy certain files. But this is where it infuriates me: It only copies certain files! I tried to change my directory structure, the file names, the number of files I wanted to copy, the code (in every possible way), but I just can't get it. So here it is:
use File::Copy; $dir="C:/Users/Beni/Documents/Master 2/_DOSSIERS/_Perl/dossiertest"; $cpt=0; print"Souhaitez-vous supprimer les fichiers copies du dossier racine u +ne fois la copie terminee ? (oui/non) : "; chomp ($del = <>); opendir(DIR,$dir); while($folder=readdir (DIR)) { if ( -f "$dir/$folder") { $folder =~m/(.+)?\.(.+)?/; if ( -d "$dir/Fichiers $2") { copy ("$folder","$dir/Fichiers $2/$folder"); } else { $dirr = $dir . '/' . "Fichiers " . $2; mkdir ("$dirr"); open (DIRR,$dirr); copy ("$folder","$dir/Fichiers $2") ; close (DIRR); } $cpt++; if ($del=~m/^oui$/i) { unlink ("$dir/$folder"); } } } print"$cpt copies effectuees"; close (DIR);
I am no Perl expert, I am currently finishing my Master's degree in Translation and I really need this code to work to finally get it over with. What I am asking for is just to understand what goes wrong with it... Can you help me? Thanks a bunch! Ben
In reply to Perl - Copy files to a newly created folder by Benichouniev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |