NEWDATE

Hello, I've got this problem. I've got this variable $filename which remains in the directory $pad. I want to change the date of $filename in that of today. I've got the next lines of code that should do the trick I think but when I run the script and take a look with WS-FTP at the file it still has got the same old date. Hope there is someone out there who can help me ??!

$pad='../test/';
$filename="test.dat";
opendir(DIR, $PAD) or print "Directory not found";
touch $pad/$filename or print "File not found";
print "You're account has been updated";
oostwijkAsked:
Who is Participating?
 
maneshrConnect With a Mentor Commented:

change

if (-e $fullpath2file){
                     $message=`touch $fullpath2file`;
                   }


TO

if (-e $fullpath2file){
                     $message=`touch $fullpath2file`;
                   }else{
  print "File does not exit\n";
  exit;
}
0
 
ahoffmannCommented:
# did you want to write
opendir(DIR, $pad) or print "Directory not found";
system(("touch $pad/$filename") or print "File not found";
0
 
oostwijkAuthor Commented:
This works but when I run the script I get the message 'File not found' though the file's date has been correctly updated. Note: there are 2 '(' characters in your answer at the second line, this gave me an error message so i took 1 '(' away. Hope that you can solve this minor problem
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
maneshrCommented:
$pad='../test/';
$filename="test.dat";
opendir(DIR, $PAD) or print "Directory not found";

where is $PAD defined??

touch $pad/$filename or print "File not found";

why do you need a / here, $pad already has a / at the end?

print "You're account has been updated";


try this.....

$pad="/something/test/";  ## use full path instead of absolute path
$filename="test.dat";

opendir(DIR, $pad) or print "Directory not found";

$fullpath2file=$pad.$filename;

if (-e $fullpath2file){
  $message=`touch $fullpath2file`;
}

if ($message){
   print "You cant touch the file\n";
}else{
   print "File has been touched!!\n";
}

0
 
ahoffmannCommented:
oops, sorry only one (, true.
remove the or clause, it's useless for the system() call.
Even the opendir() could be replaced by somthing like:
  if (-d $pad) {system("...");}
0
 
oostwijkAuthor Commented:
maneshr, you're script also resets the date but it gives the messages 'File has been touched' even when the file which has to be changed doesn't exist.
0
 
maneshrCommented:

change

if (-e $fullpath2file){
                     $message=`touch $fullpath2file`;
                   }

                   if ($message){
                      print "You cant touch the file\n";
                   }else{
                      print "File has been touched!!\n";
                   }


to
if (-e $fullpath2file){
                     $message=`touch $fullpath2file`;
                   }else{
  print "File does not exit\n";
  exit;
}

                   if ($message){
                      print "You cant touch the file\n";
                   }else{
                      print "File has been touched!!\n";
                   }
0
 
oostwijkAuthor Commented:
Ok, that does the job. thanks...
0
All Courses

From novice to tech pro — start learning today.