473,587 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to Rename a file in perl

2 New Member
Hi,

I am a total novice to perl. I am moving files from one directory to another and trying to rename a file appending the timestamp. But for some reason, my code is not able to rename.

Attached is the code :

# directory structure for input and archive files
$inputDir = "\\interac\\Dat a\\imntran\\".$ ARGV[0];
$archDir = "\\interac\\Dat a\\imntran\\Arc hive\\".$ARGV[0];
$archSQLLogDir = $archDir."\\SQL log";

die "Can not open archive directory"
unless (opendir ARCDIR, $archDir);

mkdir($archSQLL ogDir, 0777)
unless (opendir ARCLOGDIR, $archSQLLogDir) ;

# moving the files from input directory to the archive directory
$mvString = "move ".$inputDir."\\ *.dat ".$archDir."\\" ;

# looping to
while ($fn = readdir ARCDIR)
{
if (substr($fn,0,1 ) ne "." and substr($fn,0,3) ne "SQL")
{
$fn =~ /.dat/ ? $fn =~ /:|MemberTranArc hive/ ? ($dummy = $fn) : &mvFile($archDi r,$fn) : ($dummy = $fn);
}
}

closedir ARCDIR;

# subroutine

sub mvFile
{
my $dir = $_[0];
my $file = $_[1];
my $infile = $file;
my $string = "";

$file =~ s/.dat//g;
if($infile =~ /dat/)
{
$string = "move ".$dir."\\".$in file." ".$dir."\\".$fi le."_".&UnixDat e("today","%d%b %H-%M").".dat";
}

Can anyone please figure out why the code is not doing what is intended to be done?

Thanks for your help.
Feb 7 '07 #1
1 2147
KevinADC
4,059 Recognized Expert Specialist
are you trying to use a shell command "move"? You need to use the qx// operator or backtiks or probably system() since you're not returing any output from the shell, but not double-quotes.

You can also use the rename() function or the File::Copy module to move files with perl.

http://perldoc.perl.org/functions/rename.html
http://perldoc.perl.org/File/Copy.html
Feb 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3764
by: Hugz | last post by:
Hello, And Thank you for taking time to help me.Myself Hugz.I am new to perl and want to write my own Scripts.But i can't understand how perl "rename" function and "file locking" works. Actually i am running a WinME with ActivePerl 5.8.0, what i want to know is 1.What do you mean by "file creation (and deletion) is not atomic over NFS" ?
1
1972
by: jonathan184 | last post by:
trying to rename filenames and extensions then add a header in line1 of each file if the header existed in line 1 to go to the next file. but i am getting error explciti errors Here is my code I am using #!/usr/bin/perl user warnings;
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14046
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
5903
by: Mac Campbell | last post by:
For some unknown reason my mdb seemed to drop a module I had named "Utilities". I tried to copy the module back in from a backup copy and got the error message "<<MyProject>> is currently unable to rename the form, report, or module to 'Utilities' ... Close the database, reopen it, and try the rename operation again." This didn't work. It seemed...
5
2280
by: mythili123 | last post by:
The script will rename all files in the current directory whose names contain the first argument by replacing that part of the filename with the second argument. so far i could just get the file names that matches $ARGV.I need help on how to rename the files .For ex if argumnets are a bbb if a file name is rename.txt then O/P must be...
5
7815
by: eranshuman | last post by:
Hi, I m very new to perl I m running an API which have the Buil.pl When Im compiling using perl Build.pl I was getting error : Can't locate Module/Build.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/li b .) at Build.PL line 5.
2
3490
by: tanichka | last post by:
Hello you helpful folk! Please look at my script and tell me what I am doing wrong! I am cleaning the names of my music files from unnecessary symbols, and the cleaning works fine, however the perl rename function fails to do the actual renaming. I tried to rename a file in the same dir using strings instead of variables and that works!! But it...
1
5511
by: srikantvm | last post by:
Hi All, I am using perl, v5.8.8 built for MSWin32-x86-multi-thread and i tried installing the DBD-Oracle module but unable to install. Please find below the steps followed by me: 1) I first tried installing Oracle.pm using the Activestate PPM but, i got an connection error to the activestate perl module repository. 2) Then i tried...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.