Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Follow up.

meshtebmeshteb Posts: 47Member
I appreciate your help very much(& your kindness). What I dont understand here, is where are the new renamed files going to be stored in curDir or what?

When I run the command ,I get this error:

D:Scripts>CopyFiles.pl
Name "main::startDir" used only once: possible typo at d:ScriptsCopyFiles.pl line 33.


#!/usr/local/bin/perl -w

use File::Copy;

#copy $oldname, $newname;

my $startFolder = 'E:/timit/train';

opendir (DIR, $startFolder) || die "Can't access $startFolder";
my @dirs = ();
foreach (readdir(DIR)) {
# Ignore "special" directories '.' and '..'.
next if /^.+$/;

# Do -d test to make sure it is a directory.
-d && push @dirs, "$startFolder/$_";
}
closedir DIR;

my $curNum = 1;
my $curDir;
foreach $curDir (@dirs) {
opendir (DIR, $curDir) || die "Can't access $curDir";
foreach (readdir(DIR)) {
# Skip if it ain't a file.
next unless (-f&&/.wav$/i);

# Get the extension of the file - that's all we want.
/.(w+)$/;
my $extension =$1;

# Copy the file.
copy "$curDir/$_", "$startDir/training$curNum.$extension";

# Increment our counter.
$curNum ++;
}
closedir DIR;
}


Comments

  • JonathanJonathan Posts: 2,914Member
    : I appreciate your help very much(& your kindness). What I dont
    : understand here, is where are the new renamed files going to be
    : stored in curDir or what?
    :
    : When I run the command ,I get this error:
    :
    : D:Scripts>CopyFiles.pl
    : Name "main::startDir" used only once: possible typo at d:ScriptsCopyFiles.pl line 33.
    :
    Damm...what was I on when I wrote this...

    : # Copy the file.
    : copy "$curDir/$_", "$startDir/training$curNum.$extension";
    $startDir should be $startFolder - so they get copied to the folder containing the other folders - what you wanted, right?

    Sorry, I really should have been more consistent in my use of "Dir" throughout it rather than "Folder". Thanks for posting the error, I may not have caught it otherwise.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • meshtebmeshteb Posts: 47Member
    Thanx for replying. There is no error so far after making that change of StartDir to StartFolder,but there is no ouput( required results). Whats wrong?
  • JonathanJonathan Posts: 2,914Member
    : Thanx for replying. There is no error so far after making that
    : change of StartDir to StartFolder,but there is no ouput( required
    : results). Whats wrong?
    :
    My (pretty awful) code is what's wrong. For the -d and -f tests I forgot to throw the current paths on the front of the file and directory names being tested. Sorry.

    [code]#!/usr/local/bin/perl -w

    use File::Copy;

    #copy $oldname, $newname;

    my $startFolder = 'C:/Documents and Settings/Jonathan/Desktop/AMaMP';

    opendir (DIR, $startFolder) || die "Can't access $startFolder";
    my @dirs = ();
    foreach (readdir(DIR)) {
    # Ignore "special" directories '.' and '..'.
    next if /^.+$/;

    # Do -d test to make sure it is a directory.
    push (@dirs, "$startFolder/$_") if -d "$startFolder/$_";
    }
    closedir DIR;

    my $curNum = 1;
    my $curDir;
    foreach $curDir (@dirs) {
    opendir (DIR, $curDir) || die "Can't access $curDir";
    foreach (readdir(DIR)) {
    # Skip if it ain't a file.
    next unless (-f "$curDir/$_" && /.wav$/i);

    # Get the extension of the file - that's all we want.
    /.(w+)$/;
    my $extension =$1;

    # Copy the file.
    copy "$curDir/$_", "$startFolder/training$curNum.$extension";

    # Increment our counter.
    $curNum ++;
    }
    closedir DIR;
    }[/code]

    That's the last time I post a bunch of code without testing it first... :-(

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • meshtebmeshteb Posts: 47Member
    From what i've seen from your code, is that the "my $startFolder"is just one folder with all the files in it.So the code is going to copy all the files in that folder only with the extension WAV.

    So initially I said that this folder (i.e. "my $startFolder") is having many subfolders in it,where every subfolfer is having different files.But i'm interested in the WAV files only.So the code must be able to copy all the WAV files in each subfolders and put them in the (one)big folder which is "my $startFolder".

    If i'm having 5 subfolders in this "my $startFolder" folder,with each subfolder containing 2 WAV files in it .Then in the big folder("my $startFolder") i must have 10 WAV files,but being renamed as u've indicated in the code. i.e. training1.wav,....,training10.wav. So the code must be able to copy 2 files(wav) from each subfolder and put in the big folder.At the ultimate end, there will be 10 files.

    I hope you'll understand me.
    : : Thanx for replying. There is no error so far after making that
    : : change of StartDir to StartFolder,but there is no ouput( required
    : : results). Whats wrong?
    : :
    : My (pretty awful) code is what's wrong. For the -d and -f tests I forgot to throw the current paths on the front of the file and directory names being tested. Sorry.
    :
    : [code]#!/usr/local/bin/perl -w
    :
    : use File::Copy;
    :
    : #copy $oldname, $newname;
    :
    : my $startFolder ='C:/Documents and Settings/Jonathan/Desktop/AMaMP';
    :
    : opendir (DIR, $startFolder) || die "Can't access $startFolder";
    : my @dirs = ();
    : foreach (readdir(DIR)) {
    : # Ignore "special" directories '.' and '..'.
    : next if /^.+$/;
    :
    : # Do -d test to make sure it is a directory.
    : push (@dirs, "$startFolder/$_") if -d "$startFolder/$_";
    : }
    : closedir DIR;
    :
    : my $curNum = 1;
    : my $curDir;
    : foreach $curDir (@dirs) {
    : opendir (DIR, $curDir) || die "Can't access $curDir";
    : foreach (readdir(DIR)) {
    : # Skip if it ain't a file.
    : next unless (-f "$curDir/$_" && /.wav$/i);
    :
    : # Get the extension of the file - that's all we want.
    : /.(w+)$/;
    : my $extension =$1;
    :
    : # Copy the file.
    : copy "$curDir/$_", "$startFolder/training$curNum.$extension";
    :
    : # Increment our counter.
    : $curNum ++;
    : }
    : closedir DIR;
    : }[/code]
    :
    : That's the last time I post a bunch of code without testing it first... :-(
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • JonathanJonathan Posts: 2,914Member
    : From what i've seen from your code, is that the "my $startFolder"is just one folder with all the files in it.So the code is going to copy all the files in that folder only with the extension WAV.
    :
    : So initially I said that this folder (i.e. "my $startFolder") is having many subfolders in it,where every subfolfer is having different files.But i'm interested in the WAV files only.So the code must be able to copy all the WAV files in each subfolders and put them in the (one)big folder which is "my $startFolder".
    :
    : If i'm having 5 subfolders in this "my $startFolder" folder,with each subfolder containing 2 WAV files in it .Then in the big folder("my $startFolder") i must have 10 WAV files,but being renamed as u've indicated in the code. i.e. training1.wav,....,training10.wav. So the code must be able to copy 2 files(wav) from each subfolder and put in the big folder.At the ultimate end, there will be 10 files.
    :
    : I hope you'll understand me.
    :
    This is what it does - I tested it this morning.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.