Auto generate copy actions

Tools by the phpBBModders team and Community contributed tools.
Forum rules
Only post tools related to modding in here, simple.
Post Reply
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Auto generate copy actions

Post by igorw »

This script will auto generate modx copy actions for your files. Adjust the './root/' path. :)

Code: Select all

<?php
/**
*
* @copyright (c) 2008 evil3
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

function modx_from_to($root, $dir = '')
{
   foreach (scandir($root . $dir) as $file)
   {
      if ($file != '.' && $file != '..' && $file != '.svn')
      {
         if (is_file($root . $dir . $file))
         {
            echo '<file from="root/' . $dir . $file . '" to="' . $dir . $file . '" />' . "\n";
         }
         else
         {
            modx_from_to($root, $dir . $file . '/');
         }
      }
   }
}

header('Content-type: text/plain');
modx_from_to('./root/');

?>
User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Auto generate copy actions

Post by EY »

:o This will copy X file to X location????!?!?

Wow nice job!
Never Say Never!
User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Auto generate copy actions

Post by EY »

Where do we put this file?
Never Say Never!
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: Auto generate copy actions

Post by igorw »

No, it will not copy the files.
It will generate the actions like this for your modx file:

Code: Select all

<file from="root/mod.php" to="mod.php" />


You run it on a local webserver.
User avatar
Lord Le Brand
Past Contributor
Past Contributor
Posts: 223
Joined: 08 Sep 2006, 15:44
Real name: Leroy
Location: Parkstad, Limburg, the Netherlands (GMT+1)

Re: Auto generate copy actions

Post by Lord Le Brand »

Yay! this will come so handy when I'm gonna release *Project ^^ thanks Igor :beer:
Image
harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: Auto generate copy actions

Post by harmlessgoat22 »

eviL<3 wrote:No, it will not copy the files.
It will generate the actions like this for your modx file:

Code: Select all

<file from="root/mod.php" to="mod.php" />


You run it on a local webserver.

Ahh!!! I'm so mad!!! :x Yesterday or the day before I manually wrote out the copying for 110 files. I will never do that again !!!
Image
That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever
User avatar
Lord Le Brand
Past Contributor
Past Contributor
Posts: 223
Joined: 08 Sep 2006, 15:44
Real name: Leroy
Location: Parkstad, Limburg, the Netherlands (GMT+1)

Re: Auto generate copy actions

Post by Lord Le Brand »

harmlessgoat22 wrote:Ahh!!! I'm so mad!!! :x Yesterday or the day before I manually wrote out the copying for 110 files. I will never do that again !!!

Ouch!! here, have a beer on me: :beer: :mrgreen:
Image
harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: Auto generate copy actions

Post by harmlessgoat22 »

In the US, I am not old enough to drink. But I think I can on international boards. :beer:
Image
That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever
User avatar
Lord Le Brand
Past Contributor
Past Contributor
Posts: 223
Joined: 08 Sep 2006, 15:44
Real name: Leroy
Location: Parkstad, Limburg, the Netherlands (GMT+1)

Re: Auto generate copy actions

Post by Lord Le Brand »

Hmm, just wondering if you should change this line:

Code: Select all

if ($file[0] != '.')

Because it also skips .htaccess files that might be needed, if I'm not mistaken.
Image
User avatar
Mighty Gorgon
New member
New member
Posts: 44
Joined: 25 Jul 2007, 12:34
Real name: Luca
Location: Italy
Contact:

Re: Auto generate copy actions

Post by Mighty Gorgon »

That line only skips same level folder link.

I usually add also this:

Code: Select all

$file[0] != '..'


Because on linux based systems that is used for parent folders... so you prevent parsing of all parent folders as well. In Windows you should not have this issue.

.htaccess shouldn't be skipped... unless the file is hidden or you don't have the permission to list.

Also SCANDIR function requires PHP 5.

Please Igor correct me if I'm wrong. :)

EDIT:
I was wrong, I didn't read the code accurately.
Take a look at this for further reference:
http://it2.php.net/manual/en/function.scandir.php#81735
Last edited by Mighty Gorgon on 21 Jul 2008, 14:05, edited 1 time in total.
Luca
User avatar
Lord Le Brand
Past Contributor
Past Contributor
Posts: 223
Joined: 08 Sep 2006, 15:44
Real name: Leroy
Location: Parkstad, Limburg, the Netherlands (GMT+1)

Re: Auto generate copy actions

Post by Lord Le Brand »

No, the line will check the first character of the $file string, so it includes all files and folders starting with a dot, including '.', '..', '.svn', '.htaccess', etc.

I think something like this would do the trick:

Code: Select all

if ($file[0] != '.' || preg_match('#^\.ht#', $file))
Image
User avatar
Mighty Gorgon
New member
New member
Posts: 44
Joined: 25 Jul 2007, 12:34
Real name: Luca
Location: Italy
Contact:

Re: Auto generate copy actions

Post by Mighty Gorgon »

There is always something to learn... :)

Thanks, I didn't know that you can automatically get the first char of the string by considering it an array.

You are right, I also checked with php.net and found exactly what you are saying.

http://it2.php.net/manual/en/function.scandir.php#81735

I'm going to edit my previous post then. Sorry for being so superficial. :)
Luca
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: Auto generate copy actions

Post by igorw »

Let me clear things up (leroy was correct).

$file is a string. You can access any character in a string using [n], so i do $file[0] to see what is in the first character of the string. If it's a dot, it will skip the file. This is my lazy way of skipping '.' and '..', but it will also skip '.htaccess'. So the right way to do it is:

Code: Select all

if ($file != '.' && $file != '..')


The reason i did it though, was to also skip .svn folders (hidden folders used internally by svn), so i'm going to add a check for that specifically.

Code: Select all

if ($file != '.' && $file != '..' && $file != '.svn')


Thanks guys, hope that clears it up in case it wasn't already. :)
Post Reply