Import multiple MD files, merge and retain file name?

Hello,
Is there a setting that makes MD imports retain file name, merge keep file name, and then exports retain file name?
I’d like to quickly merge them, then quickly export them and retain the file name on export. The way it is now, imports show the content of draft and lose the file name? Exports automatically say “Draftsexport.txt” and I’m trying not to have to do any manual typing in the file name because there are thousands of files I have to merge. It doesn’t matter if the file name is the first, last etc selected before merge since the only difference between the pre-merged file names is xxxxx(1), xxxxx(2), xxxxx(3), etc.

Is this possible?

You can manipulate and capture file names along with content in Drafts. You would do this via actions.

But, your description sounds like you are just concatenating text (Markdown) files.


If you are on Mac, you can do this by putting the files in a folder and using cat *.md >>../somefilename.md should concatenate them to a new file one level up.

If on iOS/iPadOS, then you could do the same sort of thing using a repeat loop in Shortcuts.


If you are wanting to use Drafts to do more than, or something different to file concatenation, can you provide details and perhaps a simple worked example?

1 Like

Drafts export and file actions can be configured to use any file name/extension, that’s not a problem.

Importing maintain file names could be done as well using scripting.

That said, it might not be the best tool for the job if you have sets of files like you describe. A simple Unix command in the terminal might be better.

Like this:

cat xxx\(*\).md > xxx.md

It uses the cat command to pipe the content of any markdown file in the directory named “xxx” with something in parens after it to the “xxx.md”. There are many variations.

1 Like

I think I’m suppose to say “Jinx” to @sylumer now.

4 Likes

That’s right, just need to do concatenation on them. Wasn’t even sure if the proper term.

I’m on Mac and there are several thousand files in one folder. File names are like somefilename (1), somefilename (2), somefilename (3).

That would be a terminal command right? I guess the issue is I’d have to type each file name for the command on thousands of files. Or does terminal allow me to drag and drop multiples (3 or 4 at once) and run that? Somewhat new to Mac here.

Asterisks are wildcard matches on the filename. You don’t have to type all of the filenames.

I will give it a try! Thank you

Learned a lot about terminal in the last hour, even just getting to a directory. At first I was getting permission denied, fixed that but now a bit stuck. The files look like this all in one directory:

I’m in downloads/try folder where they are stored and terminal says:

-bash: /Users/DJ/Downloads/try: is a directory
MacBook-Pro:try DJ$

trying to do concatenation on all files with similar file names. They’re all in the same folder like:

Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 3.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 4.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 5.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 6.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig.md
Highlights for Zero History by William Gibson.md
Highlights for Zero History by William Gibson(1).md
Highlights for Zero History by William Gibson(2).md
Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams.md
Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams(1).md
Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams(2).md

I’d have to specify the xxx name for each book title right? Or the asterisks will sort that out? Got stuck here with terminal saying no such file or directory, probably because I need to type the specific book name in xxx? Really appreciate the pointers as I’m trying to get my elderly father some highlights of mine to read.

*.md should be files with any file name in the current directory, with a file extension of “md”.

Did you try running the command I posted? I didn’t try it, but I think it should work.

Yep, I tried both and got one long file named notes. Might have configured it wrong, or done something wrong in terminal. I’ll try again this afternoon. Thanks again

Does the “one long file” contain all of the contents of the MD files you placed in the directory? If so, that would be what I expected, and matches what you asked for.

If something above is not accurate, in the request, or the observed output, perhaps you could clarify?

Probably my miscommunication more than anything. Your method is useful and helped me get more comfortable with terminal and the syntax.

Here’s hopefully a better explanation:

Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 3.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 4.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 5.md
Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig 6.md

Highlights for Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig.md

Was looking for end result of 3-6 concatenated like the last one into one file with that title. Same for all files in the same directory with similar names like below:

Highlights for Zero History by William Gibson(1).md
Highlights for Zero History by William Gibson(2).md

Highlights for Zero History by William Gibson.md <—- concatenated to that

Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams(1).md
Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams(2).md

Concatenated to:
Highlights for The Hitchhiker’s Guide to the Galaxy by Douglas Adams.md

Journal John’s bday (1)

Journal John’s bday concatenated to that

Random thought jan 7 (1)
Random thought jan 7 (2)
Random thought jan 7 (3)

Random thought jan 7 concatenated

Was hoping there’s some way to concatenate / merge everything (all in same folder) with similar files names into their similar file names. It doesn’t matter which order the numbered files get merged into.

I’m trying to get my elderly father much of my thoughts, highlights, journals while he’s still around so I do appreciate the help. I’ve got someone who’s helping me make a script, but if you see an easy way, I’d love to hear about it. Thanks