Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > cut a file to deplace him in an other directory...

Reply
Thread Tools

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

 
 
B.julien
Guest
Posts: n/a
 
      04-08-2004
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 !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to déplace a circle in canvas python? olsr.kamal@gmail.com Python 1 03-09-2013 08:54 PM
Problem of not knowing a famous Star Email Adress, if one of you know him please drop him a note Diplom Kaufmann Hinrichs - Siegert, Knut Computer Support 0 10-12-2007 07:12 PM
Need advice, client wants cut of my money from other client.. Mark C++ 11 09-06-2005 11:00 PM
how do I make the validator cut off other code on the page from executing? bennett@peacefire.org ASP .Net 1 06-02-2005 04:25 PM



Advertisments