help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where to start with recursive file operations


From: Pascal Bourguignon
Subject: Re: Where to start with recursive file operations
Date: 31 Oct 2004 03:55:22 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Andrei Stebkov <stebakov@tht.net> writes:

> Hi!
> 
> I would like to write a function that finds files recursively starting from
> the current directory, opens files based on given extension and does some
> operations on them. For instance, checks out the file (from CVS or
> Perforce), selects the whole buffer, indents the contents and save it.
> Also I'd like to have same kind of function that would search and replace in
> multiple files. 
> As all the problems that I listed here stem from the same root (recursive
> search) I need a few pointers about the basic built-in emacs functions of
> this domain. The function of this nature must be already written, I just
> couldn't find them.

There's a couple of little know commands in emacs that you should learn: 

    M-x apropos RET <pattern> RET

and: 

    C-h f TAB

For example, searching for "file" with:

    M-x apropos RET file RET

or for "directory" with:

    M-x apropos RET directory RET

you'd get a list of interesting functions, like directory-files or
file-expand-wildcards.


(defun map-files (function directory &optional full)
  (dolist (item (file-expand-wildcards (concat directory "/*") full))
    (if (file-directory-p item)
      (map-files function item full)
      (funcall function item))))

(map-files (function print) "/tmp" t)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]