cut a file to deplace him in an other directory...

B

B.julien

Hi !
this is the little script
#! /usr/bin/perl -W
# this program copy all files in a directory
# and deplace them in a new directory named "multimedia" if he doesn't exist
# the program create him...

use strict ;

my($targetDirFull,$targetDir,
$origDirFull,$origDir,$bit,
@allThings,$i,$file,@fileIn);

$targetDir = 'multimedia';
$targetDirFull = 'C:\multimedia' ;
$origDirFull = 'C:\Documents and Settings\julien\XXX\' ;
#-------------------------------------
#verification that "multimedia" exist-
#-------------------------------------
unless( chdir('C:\\') ) { print "Error 1..\n" ; exit(0);}
else { chdir('C:\\'); }
unless (-e $targetDir) {
print "creating directory \"multimedia\"...\n";
mkdir('multimedia',0777);
}
############################################################################
## openning the Original Dir' ;take each file and write them in "multimedia#
############################################################################
opendir(ORIG,$origDirFull) or die("the directory is unavaible !\n") ;
unless(readdir(ORIG)) {
print "Error 2.." ; exit(0);
}
else {
print "open $origDirFull ... [OK]\n";
#to list all files in the directory
@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 = <INPUT>;
close(INPUT);

opendir(TARGET,$targetDir."\"") or die ("computer crazy !..\n");
open(OUTPUT,">".$file) or die ("Error 4..\n");
foreach $bit (@fileIn) {
print OUTPUT $bit ;
}
close(OUTPUT);
closedir(TARGET);
}
}
}
#######END OF SCRIPT######
thanks for all !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top