I have this code which lists lots of information about files and folders. I would like it to list as much as possible different information about file/folder, is there any way i can improve that gibberish? Thanks
set F to quoted form of POSIX path of (choose folder)
set folder_name to (POSIX path of (path to desktop) & "list.txt")
set L to do shell script "ls -R -F -P -l -T -a -e -i -o -p -q " & F & " > " & folder_name --with administrator privileges
Since unix commands are totally strange for me, i just readed thru ls man page and put something to my script. Improvement would be anything which collects more information about files/folders/aliases/etc.
You can use info for, and you can use the Spotlight’s mdls function:
set f to choose file
set pf to quoted form of POSIX path of f
-- info for
set I to info for f -- a record
-- spotlight info
set SI to paragraphs of (do shell script "mdls " & pf)
set F to quoted form of POSIX path of (choose folder)
set folder_name to (POSIX path of (path to desktop) & "list.txt")
set L to do shell script "ls -R -F -P -l -T -a -e -i -o -p -q " & F & " > " & folder_name --with administrator privileges
But it gives these errors:
ls: 18: Bad file descriptor
ls: 21: Bad file descriptor
ls: 3: Bad file descriptor
ls: 4: Bad file descriptor
ls: 5: Bad file descriptor
ls: 19: directory causes a cycle
ls: 22: directory causes a cycle
If this last error means that i have aliases which might create infinite loop then how i can find these aliases?
It sounds like ls is trying to process the /dev/fd directory. It is a special directory that contains something like an alias for each file that is held open by the process that scans the directory. It is normally only used in tricky shell scripting situations where you need access to an already open file, but your command only takes file paths.
If you can live with potential for some odd results in your output, then you can just suppress the error messages by running a successful command after the ls:
do shell script "ls -R -F -P -l -T -a -e -i -o -p -q " & F & " 2>&1 > " & folder_name & ";true"
Since ls skips the noted directories (along with issuing the error message), this might be OK, depending on your requirements.
If you can not live with the possibility of odd output or missed error messages, then you will probably have to move to a different solution, as ls does not have a documented way to exclude specific items during its recursive processing.
One solution might be to use separate file selection and file listing processes, you might team ls up with find and xargs. The find command is a generic filesystem recursing command. It can do various kinds of testing on files as it recurses and decide to execute commands for them, print out their names, or just ignore them. The xargs command is a generic argument grouping command. It reads individual arguments from its input and batches them up into efficient groups for processing by other commands.
To skip all “*/dev/fd” paths (which may exclude other things if you have a file or directory named fd inside a directory named dev):
do shell script "find " & F & " -path '*/dev/fd' -prune -o -print0 | xargs -0 ls -d -F -P -l -T -a -e -i -o -p -q"
Or, since the /dev/fd directory is actually a different mounted (virtual) filesystem, you could use the -x option to find instead. This option prevents find from crossing a mount point when doing its recursive processing. That means that it would not descend into other mounted volumes (local and network, both), which might be a good thing, too.
do shell script "find -x " & F & " -print0 | xargs -0 ls -d -F -P -l -T -a -e -i -o -p -q"
Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)