Trouble moving directory

Trouble moving directory

am 13.10.2005 04:11:45 von telirum

I'm having trouble moving some directories. My script works fine on some directories but doesn't
move others. It seems to have trouble with directories with non alphanumeric charters. I'm running
Red Hat FC2. I'm trying to move the directory basically like this...


$source_dir = '/some/dir/Dir That Won't Move/';
$dest_dir = '/some/other/dir/'

$cmd = escapeshellcmd("mv ".$source_dir." ".$dest_dir);
$result = shell_exec($cmd);

?>

Is there some way to escape the characters in the directories? For example if i put a "\" in front
of blank spaces it takes care of those (same for "'","(" etc.) but that obviously doesn't take
care of everything. I'm hoping there is something easy i'm overlooking here that will escape all
the characters.




-k.




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 13.10.2005 04:17:27 von Jasper Bryant-Greene

-k. wrote:
> I'm having trouble moving some directories. My script works fine on
> some directories but doesn't move others. It seems to have trouble
> with directories with non alphanumeric charters. I'm running Red Hat
> FC2. I'm trying to move the directory basically like this...
>
> >
> $source_dir = '/some/dir/Dir That Won't Move/';

$source_dir = escapeshellarg( '/some/dir/Dir That Won't Move/' );

> $dest_dir = '/some/other/dir/';

$dest_dir = escapeshellarg( '/some/other/dir/' );

>
> $cmd = escapeshellcmd("mv ".$source_dir." ".$dest_dir); $result =
> shell_exec($cmd);
>
> ?>
>
> Is there some way to escape the characters in the directories? For
> example if i put a "\" in front of blank spaces it takes care of
> those (same for "'","(" etc.) but that obviously doesn't take care of
> everything. I'm hoping there is something easy i'm overlooking here
> that will escape all the characters.

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 13.10.2005 04:48:15 von telirum

--- Jasper Bryant-Greene wrote:
> $source_dir = escapeshellarg( '/some/dir/Dir That Won't Move/' );


Unfortunately escapeshellarg doesn't work for all cases, it will escape the " ' " in that example
but it doesn't escape other characters such as " ) ". So...

$source_dir = escapeshellarg( '/some/dir/Dir That (Won't Move)/' );

....fails as well. Any other ideas?




-k.



__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 13.10.2005 13:07:22 von Robin Vickery

On 10/13/05, -k. wrote:
> --- Jasper Bryant-Greene wrote:
> > $source_dir =3D escapeshellarg( '/some/dir/Dir That Won't Move/' );
>
>
> Unfortunately escapeshellarg doesn't work for all cases, it will escape t=
he " ' " in that example
> but it doesn't escape other characters such as " ) ". So...
>
> $source_dir =3D escapeshellarg( '/some/dir/Dir That (Won't Move)/' );
>
> ...fails as well. Any other ideas?

rename("/some/dir/Dir That (Won't Move)/", '/some/other/dir/');
?>

Or if you must use shell_exec(), use addcslashes() to escape the
annoying characters first.

-robin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 14.10.2005 15:11:06 von Brent Baisley

In your example, the problem is that the name has spaces, which the
shell uses as a delimiter. So "That Won't Move/" is kind of being
considered parameters instead of part of the dir. Using the command
line (i.e. shell/terminal) will give you more feedback as to what is
happening (/some/dir/Dir: No such Directory).

You need to either escape the characters or enclose it in quotes. For
me, I always find it easier to just enclose directory names in quotes.

$source_dir = '"/some/dir/Dir That Won't Move/"';


On Oct 12, 2005, at 10:11 PM, -k. wrote:

> I'm having trouble moving some directories. My script works fine on
> some directories but doesn't
> move others. It seems to have trouble with directories with non
> alphanumeric charters. I'm running
> Red Hat FC2. I'm trying to move the directory basically like this...
>
> >
> $source_dir = '/some/dir/Dir That Won't Move/';
> $dest_dir = '/some/other/dir/'
>
> $cmd = escapeshellcmd("mv ".$source_dir." ".$dest_dir);
> $result = shell_exec($cmd);
>
> ?>
>
> Is there some way to escape the characters in the directories? For
> example if i put a "\" in front
> of blank spaces it takes care of those (same for "'","(" etc.) but
> that obviously doesn't take
> care of everything. I'm hoping there is something easy i'm
> overlooking here that will escape all
> the characters.
>
>
>
>
> -k.
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 14.10.2005 15:28:27 von Miles Thompson

One of the "nice" things MSFT did was to allow spaces in directory and file
names. It created more work for programmers.

One of the LOUSIEST things MSFT did was allowing spaces in directory and
file names, because of the needless, tedious parsing and checking it requires.

So much simpler to train users that computers are dumb and trip over
spaces, so just use an underscore where you want to separate words. Funny
thing, users accept that.

Glad I got that off my chest - Miles

At 10:11 AM 10/14/2005, Brent Baisley wrote:
>In your example, the problem is that the name has spaces, which the
>shell uses as a delimiter. So "That Won't Move/" is kind of being
>considered parameters instead of part of the dir. Using the command
>line (i.e. shell/terminal) will give you more feedback as to what is
>happening (/some/dir/Dir: No such Directory).
>
>You need to either escape the characters or enclose it in quotes. For
>me, I always find it easier to just enclose directory names in quotes.
>
>$source_dir = '"/some/dir/Dir That Won't Move/"';
>
>
>On Oct 12, 2005, at 10:11 PM, -k. wrote:
>
>>I'm having trouble moving some directories. My script works fine on
>>some directories but doesn't
>>move others. It seems to have trouble with directories with non
>>alphanumeric charters. I'm running
>>Red Hat FC2. I'm trying to move the directory basically like this...
>>
>> >>
>>$source_dir = '/some/dir/Dir That Won't Move/';
>>$dest_dir = '/some/other/dir/'
>>
>>$cmd = escapeshellcmd("mv ".$source_dir." ".$dest_dir);
>>$result = shell_exec($cmd);
>>
>>?>
>>
>>Is there some way to escape the characters in the directories? For
>>example if i put a "\" in front
>>of blank spaces it takes care of those (same for "'","(" etc.) but
>>that obviously doesn't take
>>care of everything. I'm hoping there is something easy i'm
>>overlooking here that will escape all
>>the characters.
>>
>>
>>
>>
>>-k.
>>
>>
>>
>>
>>__________________________________
>>Yahoo! Mail - PC Magazine Editors' Choice 2005
>>http://mail.yahoo.com
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>--
>Brent Baisley
>Systems Architect
>Landover Associates, Inc.
>Search & Advisory Services for Advanced Technology Environments
>p: 212.759.6400/800.759.0577
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 14.10.2005 16:46:49 von Brent Baisley

MSFT allowed spaces? They were behind in allowing spaces (and long
file names) Apple allowed them far before MS, and Unix allowed spaces
far before Apple. Unix just assumes a space is a command/parameter
delimiter first and part of the name second. Just like multiplication
takes precedence over addition unless you use parenthesis, a space
takes precedence as a delimiter unless you use quotes.
Spaces are permitted, underscores just means you don't have to use
quotes to explain what you mean. It's like saying Unix doesn't allow
you to use capitals in the file name because it won't find "filename"
it you type "FileName". It's a feature of a case sensitive file
system available in most forms of Unix. It also caused a lot of
confusion and frustration to people developing web sites under
Windows and posting to a Unix host.

Telling users to use underscores is a work around that works as long
and everyone uses underscores all the time. It's still better to have
knowledge of what's going on and why so when one does encounter a
file name with a space they know how to reference it.

I would say one of the lousiest things MSFT did was reversing the /
to reference paths in DOS.


On Oct 14, 2005, at 9:28 AM, Miles Thompson wrote:

>
> One of the "nice" things MSFT did was to allow spaces in directory
> and file names. It created more work for programmers.
>
> One of the LOUSIEST things MSFT did was allowing spaces in
> directory and file names, because of the needless, tedious parsing
> and checking it requires.
>
> So much simpler to train users that computers are dumb and trip
> over spaces, so just use an underscore where you want to separate
> words. Funny thing, users accept that.
>
> Glad I got that off my chest - Miles
>
> At 10:11 AM 10/14/2005, Brent Baisley wrote:
>
>> In your example, the problem is that the name has spaces, which the
>> shell uses as a delimiter. So "That Won't Move/" is kind of being
>> considered parameters instead of part of the dir. Using the command
>> line (i.e. shell/terminal) will give you more feedback as to what is
>> happening (/some/dir/Dir: No such Directory).
>>
>> You need to either escape the characters or enclose it in quotes. For
>> me, I always find it easier to just enclose directory names in
>> quotes.
>>
>> $source_dir = '"/some/dir/Dir That Won't Move/"';
>>
>>
>> On Oct 12, 2005, at 10:11 PM, -k. wrote:
>>
>>
>>> I'm having trouble moving some directories. My script works fine on
>>> some directories but doesn't
>>> move others. It seems to have trouble with directories with non
>>> alphanumeric charters. I'm running
>>> Red Hat FC2. I'm trying to move the directory basically like this...
>>>
>>> >>>
>>> $source_dir = '/some/dir/Dir That Won't Move/';
>>> $dest_dir = '/some/other/dir/'
>>>
>>> $cmd = escapeshellcmd("mv ".$source_dir." ".$dest_dir);
>>> $result = shell_exec($cmd);
>>>
>>> ?>
>>>
>>> Is there some way to escape the characters in the directories? For
>>> example if i put a "\" in front
>>> of blank spaces it takes care of those (same for "'","(" etc.) but
>>> that obviously doesn't take
>>> care of everything. I'm hoping there is something easy i'm
>>> overlooking here that will escape all
>>> the characters.
>>>
>>>
>>>
>>>
>>> -k.
>>>
>>>
>>>
>>>
>>> __________________________________
>>> Yahoo! Mail - PC Magazine Editors' Choice 2005
>>> http://mail.yahoo.com
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>>
>>
>> --
>> Brent Baisley
>> Systems Architect
>> Landover Associates, Inc.
>> Search & Advisory Services for Advanced Technology Environments
>> p: 212.759.6400/800.759.0577
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 14.10.2005 17:17:09 von ac

escapeshellarg() works quite well, why you say its still failed? did u try?
do a

will produce
'Dir That (Won'\''t Move)'
and this does fit into shell, even `(' and `)' is not escaped,
for in bash, all thing quoted in single quote will be treated as one
whole string and any meta character wont be interpreted by the shell.

so , please first try, then post your problem.

On 10/13/05, -k. wrote:
> --- Jasper Bryant-Greene wrote:
> > $source_dir =3D escapeshellarg( '/some/dir/Dir That Won't Move/' );
>
>
> Unfortunately escapeshellarg doesn't work for all cases, it will escape t=
he " ' " in that example
> but it doesn't escape other characters such as " ) ". So...
>
> $source_dir =3D escapeshellarg( '/some/dir/Dir That (Won't Move)/' );
>
> ...fails as well. Any other ideas?
>
>
>
>
> -k.
>
>
>
> __________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
all born, to be dead

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble moving directory

am 14.10.2005 22:18:02 von Richard Lynch

On Fri, October 14, 2005 8:28 am, Miles Thompson wrote:
> One of the "nice" things MSFT did was to allow spaces in directory and
> file
> names. It created more work for programmers.

I'm not familiar with MSFT...

It must be a new acronym for Apple MacOS :-), circa 1984, which
(AFAIK) was the first consumer OS to allow human-centric filenames.

It was considered a big boon to many users, who were sick and tired of
8.3 at that point.

Of course, Unix and Vax and various mainframes allowed all kinds of
characters in filenames...

Including control-characters, which led to some interesting effects
and pranks when crossed with various utilities that did not plan for
such characters.

But I digress...

To some degree, the current filename problem is compounded here by PHP
which works under so many different OSes.

There's no problem with spaces or apostrophes in Mac filenames or the
routines that operate upon them *IF* they are all Mac-based. The only
character most humans want to use that is illegal is the colon (:)

Similarly, if you stick solely to Windows or Linux, the rules are
fairly straight-forward. Well, as straight-forward as anything is in
Windows.

But once you start writing multi-OS code, you've got : on Mac, / on
Linux, \ on Windows, just in the directory separators. Then you start
talking about path separaters and shell arguments, and life gets
incredibly more complicated.

--
Like Music?
http://l-i-e.com/artists.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php