grmshw4 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm very new to perl and am trying to write a script that will basically say "look in a folder and if the file that is in that folder is the same as any of the files in a second folder then rename the first file by adding an "_1". There will always only be one file in the first folder but can be many in the second folder. I wrote the code below but it doesn't seem to do anything. Help would be appreciated. Thanks!
#! /usr/bin/perl use diagnostics; $tempdir="c:/Temp/OneFile"; opendir(TMP, $tempdir) || die; @onefile= readdir(TMP); closedir(TMP); $permdir="c:/Support/Files"; opendir(PMD, $permdir) || die; @allfiles= readdir(PMD); closedir(PMD); our @onefile_1; foreach $file (@allfiles) { if ($file eq "@onefile") { rename("$onefile", "@onefile_1.txt"); } } exit(0); __END__ :endofperl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing folders
by toolic (Bishop) on Jul 28, 2010 at 19:03 UTC | |
by grmshw4 (Initiate) on Jul 28, 2010 at 20:23 UTC | |
|
Re: comparing folders
by jwkrahn (Abbot) on Jul 28, 2010 at 20:30 UTC | |
by grmshw4 (Initiate) on Jul 28, 2010 at 20:43 UTC | |
|
Re: comparing folders
by morgon (Priest) on Jul 28, 2010 at 19:28 UTC | |
by grmshw4 (Initiate) on Jul 28, 2010 at 20:27 UTC |