Zettelkasten Forum


I am an idiot - help please with md to txt batch processing

JKFJKF
edited February 28 in Random

I used the script below in terminal yesterday with the objective of converting all the txt files in one directory to md documents, but I set the current directory incorrectly and converted far more than I wanted to.

I'm hoping this won't cause any core problems (if it does, this will obvs be a different conversation). Assuming so, how do I modify this script to do the opposite - i.e. convert all the md documents in the current directory to txt files? Thanks in advance :blush:

find . -iname "*.txt" -exec bash -c 'mv "$0" "${0%.txt}.md"' {} \;

Comments

  • Thank you. I'll take a look

  • @JKF

    Did you make a backup before running the above command?

    May not be as simple to reverse that command. If you had a mix of md and txt files before, doing a reverse could also be more than you want.

    If you have a backup I would make a copy of the corrupted directory as it is now and restore the backup. If the backup wasn’t current use the corrupted copy to selectively copy back files that are missing from the backup.

    Then start over.

    We almost always learn the lesson of backups the hard way. We all been there.
    Hope it works out for you.

  • Thanks mike

    I’ll be doing it (this time) on selected directories only in which there isn’t a mix of file types. If it’s had an impact at higher, mixed file level I’m probably in a lot more trouble - I’ll have to see.

  • I once wrote a shell tool for batch file renaming which might help you here:

    http://grep.extracts.de/greprename/

    Due to its use of per-style regular expression syntax, it offers a lot of power (see the "Examples" section). The script also displays all proposed file name changes before actually doing anything (you have to actively accept the proposed changes for the rename action to happen). This review step helps to avoid issues.

    In addition, every file renaming action (as well as any errors that occur) will be written to a log file (by default located at ~/Documents/greprename.log). You can always open this log file in any text editor to see what files got renamed or what went wrong. The log file can even be used to revert any erroneous renaming action:

    http://applescript.extracts.de/scripts/finder/Grep_Rename_Revert.html

  • @msteffens said:
    I once wrote a shell tool for batch file renaming which might help you here:

    http://grep.extracts.de/greprename/

    Due to its use of per-style regular expression syntax, it offers a lot of power (see the "Examples" section). The script also displays all proposed file name changes before actually doing anything (you have to actively accept the proposed changes for the rename action to happen). This review step helps to avoid issues.

    In addition, every file renaming action (as well as any errors that occur) will be written to a log file (by default located at ~/Documents/greprename.log). You can always open this log file in any text editor to see what files got renamed or what went wrong. The log file can even be used to revert any erroneous renaming action:

    http://applescript.extracts.de/scripts/finder/Grep_Rename_Revert.html

    Oh fantastic, thank you

Sign In or Register to comment.