0

I am trying to parse file permissions using string-match. My code is,

(setq fmode (nth 8 (file-attributes "/Users/sk/a.js")))
(message "file mode is as, - %s" fmode)
(string-match "^.\\(...\\)\\(...\\)\\(...\\)$" fmode)
(message "User permission -  %s" (match-string 1))
(message "Group permission - %s" (match-string 2))
(message "Others permission - %s" (match-string 3))

It outputs,

file mode is as, - -rw-r--r--
User permission -  (se
Group permission - tq 
Others permission - fmo

As one can see, instead of parsing the file mode string, -rw-r--r--, string-match parses the buffer contents from the beginning position.

My case is very similar to the documented example here, but i am clueless why it doesn't work?

1 Answer 1

1

string-match works fine but match-string gets the group contents from the wrong object, namely the current buffer.

You must pass the original string to match-string as second argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.