(original) (raw)

(defun icalendar-get-in-dir (indir) ;; returns calendars in directory (interactive "Directory:" ) ;; calendars are kept in ~/Library/Calendars/ (let (el-files-list (current-directory-list (directory-files-and-attributes indir))) ;; (while current-directory-list (cond ((> 7 (length (car (car current-directory-list)))) ()) ((equal ".caldav" (substring (car (car current-directory-list)) -7)) (setq el-files-list (cons (concat (concat indir "/") (car (car current-directory-list))) el-files-list))) ) ;; move to the next filename in the list; this also ;; shortens the list so the while loop eventually comes to an end (setq current-directory-list (cdr current-directory-list))) ;; return the filenames el-files-list)) (defun icalendar-get-filelist (indir endstr) ;; get a list of all calendars in a directory... (let (el-files-list (current-directory-list (directory-files-and-attributes indir))) ;; (while current-directory-list (cond ((> (length endstr) (length (car (car current-directory-list)))) ()) ((equal endstr (substring (car (car current-directory-list)) (- 0 (length endstr)))) (setq el-files-list (cons (car (car current-directory-list)) el-files-list))) ) ;; move to the next filename in the list; this also ;; shortens the list so the while loop eventually comes to an end (setq current-directory-list (cdr current-directory-list))) ;; return the filenames el-files-list)) (defun icalendar-convert-all () (interactive) (let ((topdir "~/Library/Calendars")) (setq dirlist (icalendar-get-filelist topdir ".caldav")) (while dirlist (setq dd (concat (concat topdir "/") (car dirlist))) (setq callist (icalendar-get-filelist dd ".calendar")) (while callist (setq dd (concat (concat (concat dd "/") (car callist)) "/Events")) (setq icslist (icalendar-get-filelist dd ".ics")) (shell-command-to-string "touch /Users/jklymak/idiary") (setq d0 dd); (find-file "/Users/jklymak/icsdiary") (kill-buffer (buffer-name)) (shell-command-to-string "rm /Users/jklymak/icsdiary") (while icslist (setq dd (concat (concat d0 "/") (car icslist))) (icalendar-import-file dd "/Users/jklymak/icsdiary") (set-buffer (find-file dd)) (kill-buffer (buffer-name)) (setq icslist (cdr icslist))) (set-buffer (find-file "/Users/jklymak/icsdiary")) (kill-buffer (buffer-name)) (shell-command-to-string (concat "mv -f /Users/jklymak/icsdiary /Users/jklymak/Plans/diary")) (setq callist (cdr callist))) (setq dirlist (cdr dirlist))) callist)) (provide 'icalendar-convertall)