Distinguishing files with extensions, from hidden files and no extensions

前端 未结 1 1481
刺人心
刺人心 2020-12-07 05:32

I\'m having difficulty distinguishing files with extensions, from files without extensions, and hidden files. I\'m using (file-name-extens

相关标签:
1条回答
  • 2020-12-07 06:25

    How about

    (let* ((input-regexp '("odt" "wpd" "docx" "doc" "xls" "pdf" "tif" "bmp" "jpg"))
           (input-filename (dired-get-file-for-visit))
           (ext (file-name-extension input-filename)))
      (unless (and ext (regexp-match-p input-regexp ext))
        (find-file input-filename)))
    

    Alternatively, redefine

    (defun regexp-match-p (regexps string)
      (and string
           (catch 'matched
             (let ((inhibit-changing-match-data t)) ; small optimization
               (dolist (regexp regexps)
                 (when (string-match regexp string)
                   (throw 'matched t)))))))
    
    0 讨论(0)
提交回复
热议问题