Talk:Walk a directory/Recursively: Difference between revisions

 
(5 intermediate revisions by 3 users not shown)
Line 47:
}
</lang> will succeed on openning a symlinked dir (it makes sense), and that's the thing one needs to check for. --[[User:Ledrug|Ledrug]] 00:53, 14 June 2011 (UTC)
:::::::Ok, you are right that -d under perl does the wrong thing for a terminating recursive traversal. That said, the perl implementation does not seem to be using -d for that purpose. Similarly, the C implementation uses stat, and not opendir, to recognize directories. Even the zsh implementation is doing the right thing. But now I am wondering: does zsh also have the issue where paths such as ../foo are manipulated by the shell before being passed to the operating system? --[[User:Rdm|Rdm]] 12:22, 14 June 2011 (UTC)
::::::: This script<lang bash>#!/usr/bin/zsh
cd /tmp
mkdir dir1 dir2
ln -s dir1 symlink
 
cd dir1; pwd
cd ../dir2; pwd
cd ..; pwd
cd symlink; pwd
cd ../dir2; pwd</lang>says: <lang>/tmp/dir1
/tmp/dir2
/tmp
/tmp/symlink
/tmp/dir2</lang>
Which doesn't seem to do anything unexpected. --[[User:Ledrug|Ledrug]] 17:20, 14 June 2011 (UTC)
 
::::::: I was thinking more like this: <lang bash>#!/usr/bin/bash
mkdir dir1 dir2
cd dir2
ln -s ../dir1
mkdir dir2
cd dir1
(cd -P .; cd ../dir2; pwd -P)
(cd .; cd ../dir2; pwd -P)
</lang> When I run that in the directory /tmp/t, I get: <lang>/tmp/t/dir2
/tmp/t/dir2/dir2</lang> That said, the behavior now is much better than what it used to be. If I remove the second mkdir line, and delete the directories and run that again, I get <lang>/tmp/t/dir2
/tmp/t/dir2</lang> where once upon a time if I did not use cd -P . I would get an error trying to <code>cd ../dir2</code>. --[[User:Rdm|Rdm]] 20:14, 14 June 2011 (UTC)
::::::: Tested your script in zsh, result was exactly the same. --[[User:Ledrug|Ledrug]] 20:32, 14 June 2011 (UTC)
 
== Be Careful: Not Here Only ==
 
Regarding ''"Note: Please be careful when running any code examples found here"'': that applies to pretty much every problem page you see on Rosetta!!! Any program that is not completely trivial and transparent (to your eyes) can be hiding something unsavory.--[[User:Kazinator|Kazinator]] ([[User talk:Kazinator|talk]]) 21:11, 19 June 2017 (UTC)
 
: Generally speaking, you should try to comprehend what the code is doing. That said, I have not noticed any abusive code here, yet. I have seen quite a lot of abusive users but mostly they are trying for search engine pollution (which we delete, of course) rather than investing their time into getting developers run bad code. Still, the whole point of this site is to understand what's going on in a variety of contexts, so putting some effort into that is good practice for a variety of reasons. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 21:30, 19 June 2017 (UTC)
6,951

edits