Welcome to WebmasterWorld Guest from 54.146.239.96

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

How rename file in different folder ...

How rename file in different folder ...

     

StopSpam

2:22 pm on Jul 25, 2003 (gmt 0)

10+ Year Member



Dear perl guruís i have a simple renaming and path question:
the below codes renames news.dat to newsold.dat

###############
$old = "news.dat";
$new = ".newsold.dat";
rename($old, $new) or system("mv", $old, $new);
###############

But above code only works if the file news.dat is in the same directory
as the script with the above code

My Question is:

How can the above code rename a file that is in a different dir then cgi-bin script itself ..
how do i tell script the file is in different folder ...

The reason i ask this is because i am afraid if i include the path to $old like:
$old = "/home/public_html/news.dat";
i am afraid it will rename the complete dir to $new?

The path to $old is: $old = "/home/public_html/news.dat";

i have no idea how to tell the script that the file is in diff dir ...
Please advise .. thanks

marcs

7:57 pm on Jul 26, 2003 (gmt 0)

10+ Year Member



Simply use :

$old = "/home/public_html/news.dat";
$new = "/home/public_html/.newsold.dat";
rename($old, $new)

It will not rename the directory, only the file, as you want.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month