changing the date of a file on a webserver

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigalownz
    Confirmed User
    • Aug 2005
    • 1657

    #1

    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
    Last edited by bigalownz; 06-04-2008, 12:24 AM.
    $100 free credit for all hosting needs
  • testpie
    Mostly retired
    • Apr 2006
    • 3231

    #2
    Originally posted by bigalownz
    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?

    Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

    Comment

    • bigalownz
      Confirmed User
      • Aug 2005
      • 1657

      #3
      Originally posted by testpie
      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
      $100 free credit for all hosting needs

      Comment

      • testpie
        Mostly retired
        • Apr 2006
        • 3231

        #4
        Originally posted by bigalownz
        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>"
        ?>

        Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

        Comment

        • Spudstr
          Confirmed User
          • Jan 2003
          • 2321

          #5
          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.
          Managed Hosting - Colocation - Network Services
          Yellow Fiber Networks
          icq: 19876563

          Comment

          • gornyhuy
            Chafed.
            • May 2002
            • 18041

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

            icq:159548293

            Comment

            • bigalownz
              Confirmed User
              • Aug 2005
              • 1657

              #7
              Originally posted by testpie
              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
              $100 free credit for all hosting needs

              Comment

              • darksoul
                Confirmed User
                • Apr 2002
                • 4997

                #8
                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
                1337 5y54|)m1n: 157717888
                BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
                Cambooth

                Comment

                • testpie
                  Mostly retired
                  • Apr 2006
                  • 3231

                  #9
                  Originally posted by bigalownz
                  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:
                  Originally posted by darksoul
                  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...

                  Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

                  Comment

                  • bigalownz
                    Confirmed User
                    • Aug 2005
                    • 1657

                    #10
                    thanks guys for the help

                    i used

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

                    and it worked great
                    $100 free credit for all hosting needs

                    Comment

                    • bigalownz
                      Confirmed User
                      • Aug 2005
                      • 1657

                      #11
                      Originally posted by testpie

                      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
                      $100 free credit for all hosting needs

                      Comment

                      Working...