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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
maneshrCommented:

change

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


TO

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oostwijkAuthor Commented:
Ok, that does the job. thanks...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.