Closed OrionRandD closed 4 years ago
Hopefully you're on Unix or a Mac or on Windows with the Unix subsystem or Cygwin. Here's what I do when I get in this situation. Get to a shell, and cd
to the directory with your badly named files. Execute the following command. Make sure the output looks the way you expect it to. It will produce a sequence of mv
commands to rename your files. (If your files have apostrophes ('
) in the name, you'll need a bit more to make this work.)
/bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/"
When run on a directory containing a file named after your example, it produces this:
mv '10-06-2020-22:53 python_automateBSW01.org' '2020-06-10-2253 python_automateBSW01.org'
When you're satisfied this is the right output, pipe the output of that to the shell to execute the renames.
/bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/" \
| sh
Here's an example on a directory containing the file you mention:
$ ls
10-06-2020-22:53 python_automateBSW01.org
$ /bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/"
mv '10-06-2020-22:53 python_automateBSW01.org' '2020-06-10-2253 python_automateBSW01.org'
$ /bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/" \
| sh
$ ls
2020-06-10-2253 python_automateBSW01.org
(Variations on this theme are how I have migrated tons of files into the appropriate format for my Zettelkasten.)
Thx a lot for the fix! It worked greatly. I think that there should be an option/feature in zetteldeft for fixing file IDs when people face the same-like issue. But I will copy this fix to a local file in case I need it again.
Another thing is that I wonder if this setup is right or I can improve it in my init.org:
(use-package zetteldeft :ensure t :after deft :config (zetteldeft-set-classic-keybindings) (setq deft-new-file-format zetteldeft-id-format))
(defun zetteldeft-generate-id () "Generate an ID in the format of `zetteldeft-id-format'." (format-time-string zetteldeft-id-format))
(require 'zetteldeft) ;; (zetteldeft-set-classic-keybindings)
It is working, but perhaps I can improve the syntax.
Also I would like to change the auto-saving time in my deft in the init.org. I know how to change it in my deft.el, but this solution is not good because when MELPA updates deft, I have to set auto-save time again. Here is my deft setup in init.org:
(use-package deft :ensure t :custom (deft-extensions '("org" "md" "txt")) (deft-directory "~/org~/deft-notes") (deft-use-filename-as-title t))
(defun cypher/deft-open-other ()
(interactive)
(deft-open-file-other-window t))
(defun cypher/deft-open-preview ()
(interactive)
(deft-open-file-other-window))
(with-eval-after-load 'deft
(define-key deft-mode-map
(kbd "
(setq deft-strip-summary-regexp (concat "\(" "[\n\t]" ;; blank "\|^#\+[a-zA-Z_]+:.*$" ;;org-mode metadata "\)"))
I wonder where I should set the auto-save time in this deft setup to save every 30 seconds and how to add this in the above use-package configuration.
:)
With respect to zetteldeft
having an option to rename IDs, I will admit that I'm not a fan. Let zetteldeft
be zetteldeft
. I like that it focuses on making the note-taking, linking and discovery workflow nearly frictionless for me.
I've not used :custom
with use-package
. I tend to put all my initializations into the :config
section, like this:
:config
(progn
(setq deft-directory "~/Documents/ZK")
(setq deft-recursive t)
(setq deft-filter-only-filenames t)
(setq deft-file-limit 200)
(setq deft-auto-save-interval 0)
...)
The progn
isn't necessary, but I like the way things indent better and it's easier to traverse the use-package
with C-M-f
and C-M-b
.
Thx for the suggestion. I've fixed everything now. :)
I made a mistake setting up my IDs and some of my files look like this: 10-06-2020-22:53 python_automateBSW01.org The problem is that this format does not create a proper ID when I tell zetteldeft to copy the current ID. It only shows the paragraph symbol with no identification. Then I reinstalled zetteldeft and the files are ok, generating correct IDs like that: 2020-05-16-1139 python_course-AtBSwP.org Question: How do I fix my files with this ID format 10-06-2020-22:53 python_automateBSW01.org to be like this 2020-05-16-1139 python_course-AtBSwP.org. I think the (:) colon spoiled some of my files IDs. Do I have to recreate all those files copying and pasting the contents or there is a way to batch fix all the files with the (:) colon IDs?