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

Discussion in 'Perl' started by B.julien, Apr 9, 2004.

  1. B.julien

    B.julien Guest

    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 !
     
    B.julien, Apr 9, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kev
    Replies:
    0
    Views:
    415
  2. levander
    Replies:
    1
    Views:
    267
    Michael Hudson
    Jul 31, 2005
  3. moshe12007
    Replies:
    0
    Views:
    397
    moshe12007
    Apr 25, 2008
  4. Replies:
    1
    Views:
    119
    David Thielen
    Mar 12, 2006
  5. Replies:
    1
    Views:
    98
    Rick Johnson
    Mar 9, 2013
Loading...

Share This Page