GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   changing the date of a file on a webserver (https://gfy.com/showthread.php?t=832669)

bigalownz 06-04-2008 01:22 AM

changing the date of a file on a webserver
 
I got 10000's html files hosted that where from 2004 to 2006 etc

is there a script or programe i can use to change the 10000's html files date from 2005/2006 to 2008

thanks

i found a lot of file date changers on google but they only work with windows

testpie 06-04-2008 03:24 AM

Quote:

Originally Posted by bigalownz (Post 14275517)
I got 10000's html files hosted that where from 2004 to 2006 etc

is there a script or programe i can use to change the 10000's html files date from 2005/2006 to 2008

thanks

i found a lot of file date changers on google but they only work with windows

If you're using *NIX (UNIX/Linux) like I assume, couldn't you write a simple PHP script that just rips through all the files in the directory, opens them and then saves them all, changing the modified time to the day the script was run on?

bigalownz 06-04-2008 05:14 AM

Quote:

Originally Posted by testpie (Post 14275789)
If you're using *NIX (UNIX/Linux) like I assume, couldn't you write a simple PHP script that just rips through all the files in the directory, opens them and then saves them all, changing the modified time to the day the script was run on?

yes thats what im looking for
but i dont know how to write a php script like that

testpie 06-04-2008 05:57 AM

Quote:

Originally Posted by bigalownz (Post 14275983)
yes thats what im looking for
but i dont know how to write a php script like that

Here you go, just remember to change the DIR_HERE to the directory the files are in (e.g. /home/user/public_html/filedirectory/):
PHP Code:

<?php
## Variables
# Directory
$dir "DIR_HERE";

## Code
if($handle opendir($dir)) {
 print 
"<p>Processing files...</p>";
 
# Loop through files in dir
 
while(false !== ($file readdir($handle))) {
  
# Get file data
  
$data file_get_contents($file);
  
# Write data back to file
  
$fp fopen($file"w");
  
fwrite($fp$data);
  
fclose($fp);
  
# Give output
  
print "<p>Done &quot;".$file."&quot;</p>";
 }
 
# Close dir
 
closedir($handle);
}
print 
"<br /><p>Finished</p>"
?>


Spudstr 06-04-2008 06:06 AM

you can use the system command touch to change the timestamp on a file as well. no need to use all the resources to open/close a file.

gornyhuy 06-04-2008 06:27 AM

Yeah, touch is way more efficient and is designed to do exactly what you want.

bigalownz 06-04-2008 07:17 AM

Quote:

Originally Posted by testpie (Post 14276097)
Here you go, just remember to change the DIR_HERE to the directory the files are in (e.g. /home/user/public_html/filedirectory/):
PHP Code:

<?php
## Variables
# Directory
$dir "DIR_HERE";

## Code
if($handle opendir($dir)) {
 print 
"<p>Processing files...</p>";
 
# Loop through files in dir
 
while(false !== ($file readdir($handle))) {
  
# Get file data
  
$data file_get_contents($file);
  
# Write data back to file
  
$fp fopen($file"w");
  
fwrite($fp$data);
  
fclose($fp);
  
# Give output
  
print "<p>Done &quot;".$file."&quot;</p>";
 }
 
# Close dir
 
closedir($handle);
}
print 
"<br /><p>Finished</p>"
?>


thanks for your help
will it change the date on all files?
as i just want .html to change

darksoul 06-04-2008 07:22 AM

go to the directory where the files are and run this command (ssh)
Code:

find . -name "*.html" -print0|xargs -0 touch

P.S. the php script above changes all files regardless of extension

testpie 06-04-2008 07:57 AM

Quote:

Originally Posted by bigalownz (Post 14276415)
thanks for your help
will it change the date on all files?
as i just want .html to change

As darksoul said, the script I provided will change all files regardless of extension, and is admittedly exhaustive on CPU and I/O resources because it has to keep opening and closing files. You would be better off taking darksoul's advice and doing the following:
Quote:

Originally Posted by darksoul (Post 14276438)
go to the directory where the files are and run this command (ssh)
Code:

find . -name "*.html" -print0|xargs -0 touch

P.S. the php script above changes all files regardless of extension

As for me, one day I'll lock myself in a room and force myself to learn the ins and outs of Linux... one day...

bigalownz 06-07-2008 12:55 AM

thanks guys for the help

i used

find . -name "*.html" -print0|xargs -0 touch

and it worked great

bigalownz 06-07-2008 12:56 AM

Quote:

Originally Posted by testpie (Post 14276568)

As for me, one day I'll lock myself in a room and force myself to learn the ins and outs of Linux... one day...

i should


it took me years to learn windows


All times are GMT -7. The time now is 08:55 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123