# How to use file directory pattern

**URL:** <https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802>\
**Category:** Help\
**Created:** [July 12, 2021, 2:58pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802 "2021-07-12T14:58:40Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 12, 2021, 2:58pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/1 "2021-07-12T14:58:40Z")

</div>

I want to create subdirectories for attachments, similar to how previously did it with [Zotfile](http://zotfile.com/). As far as I can tell, this is the `file directory pattern` setting under `Linked Files` – however, I tried pretty much everything and cannot figure out how to get it to work. I tried the citation key tags `[]` which work with the file name pattern, but that also did not work.

 ![Screen Shot 2021-07-12 at 16.23.17](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/f28af51792b8db5f8582ae7460da95bc44a72799.png)

Following the information in [this forum post](https://discourse.jabref.org/t/file-directory-pattern-help/663), I also tried stuff like `\year` which did not work either. There also doesn’t seem to be much documentation on this subject.

Can someone help me out? My goal would be to create subdirectories like  
`[auth1]/[authEtAl]/[year]/thefile.pdf`

---

<div class="post-metadata">

**Author:** ![Siedlerchr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/siedlerchr/32/216_2.png) [@Siedlerchr](https://discourse.jabref.org/u/Siedlerchr)\
**Post date:** [July 12, 2021, 5:25pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/2 "2021-07-12T17:25:27Z")

</div>

Hi,

Your pattern is correct and works fine for me. Have you defined a main file directory?  
If you have already attached files and want them to move, you can use the Quality → Cleanup entries → Check Moe files to default file directory

 ![Bildschirmfoto 2021-07-12 um 19.22.47](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/3a6ddba57f8d8834b588388bc3499ab0cfff6b15.png)

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 12, 2021, 6:31pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/3 "2021-07-12T18:31:27Z")

</div>

Well, in that case it might be some sort of bug on my side?  
Because I have defined a main directory and have pretty much the same settings as you, but every time I drop a file on the reference entry, it the file ends up in the main file directory without any subfolders.

 ![Screen Shot 2021-07-12 at 20.22.57](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/49726c9e4e1ab961233b5d35d7786f41b9d39568.png)

---

<div class="post-metadata">

**Author:** ![k3KAW8Pnf7mkmdSMPHz2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/k3kaw8pnf7mkmdsmphz2/32/1116_2.png) [@k3KAW8Pnf7mkmdSMPHz2](https://discourse.jabref.org/u/k3KAW8Pnf7mkmdSMPHz2)\
**Post date:** [July 13, 2021, 7:15pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/4 "2021-07-13T19:15:38Z")

</div>

It works for the cases I’ve tested as well 😕

1. Would you mind showing the full `Filename format pattern`?
2. Does your main file directory exist?
3. What (if anything) happens if you manually move the file to the directory from within the JabRef entry editor?

 ![Skärmavbild 2021-07-13 kl. 15.13.36](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/45c41d928fc8dd8671925e8385f1fa94d66a76bc.png)

---

<div class="post-metadata">

**Author:** ![Siedlerchr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/siedlerchr/32/216_2.png) [@Siedlerchr](https://discourse.jabref.org/u/Siedlerchr)\
**Post date:** [July 13, 2021, 8:17pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/5 "2021-07-13T20:17:45Z")

</div>

@armenaton Could you elaborate which JabRef version you are using and on which system? (e.g. linux/snap). We both tested in the latest 5.3 release

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 8:15am UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/6 "2021-07-14T08:15:21Z")

</div>

This is the file renaming pattern. I tried the default pattern as well and it didnt make a difference though.  
`[authEtAl]_[year]_[title]_[firstpage]-[lastpage]`

The directory pattern is:  
`[auth1]/[authEtAl]/[year]`

The main file directory exists. All the – correctly renamed – files end up there. Only the creation of subdirectories is not happening.

 ![Screen Shot 2021-07-14 at 10.07.05](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/eaa2d78c89de2ad15ee5e839569de43886ff4080.png)

I am also on the latest version:

> JabRef 5.3–2021-07-05–50c96a2  
> Mac OS X 11.4 x86\_64  
> Java 16.0.1  
> JavaFX 16+8

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 8:15am UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/7 "2021-07-14T08:15:56Z")

</div>

Moving to the file directory is greyed out for me 😕

 ![Screen Shot 2021-07-14 at 10.03.24](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/33bc5e6208b525404e4fe633ba15d8fc97b3d427.png)

(sorry for the second post, I am not allowed to post multiple images yet as new user.)

---

<div class="post-metadata">

**Author:** ![k3KAW8Pnf7mkmdSMPHz2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/k3kaw8pnf7mkmdsmphz2/32/1116_2.png) [@k3KAW8Pnf7mkmdSMPHz2](https://discourse.jabref.org/u/k3KAW8Pnf7mkmdSMPHz2)\
**Post date:** [July 14, 2021, 4:44pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/8 "2021-07-14T16:44:04Z")

</div>

This is weird. The greyed-out makes sense thinking about it. It should be greyed out if the file already has the directory and file name that JabRef believes it should, and therefore believes there is nothing to do.

What if you only put a directory name in the directory pattern?

instead of

```auto
[auth1]/[authEtAl]/[year]

```

just put

```nohighlight
Debugging

```

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 5:51pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/9 "2021-07-14T17:51:17Z")

</div>

I just tried it, the fiel still gets placed into the main file directory. No “debugging” subdirectory is created.

 ![Screen Shot 2021-07-14 at 19.47.30](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/9988894b74b3de0d1304c5a131057d07afd6d720.png)

I also tried reinstalling Jabref and creating a new library for testing. Issue still persists.

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 6:21pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/10 "2021-07-14T18:21:56Z")

</div>

Okay, I experimented a bit and it seems that this is a bug related to the drag & drop function.

With this workaround, everything works as it is supposed to:

> rightclick entry ➞ attach file ➞ select pdf ➞ double-click entry to open ➞ Tab “General” ➞ scroll down to “File” ➞ rightclick the attachment ➞ select the “Move file to file directory and rename” (which is not greyed out now)

Now the subdirectories are created.

Obviously, this is an annoyingly tedious process compared to simply using drag & drop. Especially when you have to do it regularly. But it seems to further indicate that some bug is at work here. 😕

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 6:37pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/11 "2021-07-14T18:37:30Z")

</div>

well this is weird. After experimenting a bit more, I got this error message.

 ![Screen Shot 2021-07-14 at 20.24.07](https://canada1.discourse-cdn.com/flex030/uploads/jabref/original/1X/4a711ca66f4c6a6d83329feb82313ab04fe86d9a.png)

in the details is the following error message.

```auto
java.lang.UnsupportedOperationException: Flush is forbidden from target!
	at org.jabref.merged.module@5.3.60000/com.sun.glass.ui.View$2.flush(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.QuantumClipboard.flush(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.QuantumToolkit.startDrag(Unknown Source)
	at org.jabref.merged.module@5.3.60000/javafx.scene.Scene$DnDGesture.dragDetectedProcessed(Unknown Source)
	at org.jabref.merged.module@5.3.60000/javafx.scene.Scene$DnDGesture.process(Unknown Source)
	at org.jabref.merged.module@5.3.60000/javafx.scene.Scene$MouseHandler.process(Unknown Source)
	at org.jabref.merged.module@5.3.60000/javafx.scene.Scene.processMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.3.60000/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.glass.ui.View.notifyMouse(Unknown Source)
	at org.jabref.merged.module@5.3.60000/com.sun.glass.ui.mac.MacView.notifyMouse(Unknown Source)

```

---

<div class="post-metadata">

**Author:** ![k3KAW8Pnf7mkmdSMPHz2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/k3kaw8pnf7mkmdsmphz2/32/1116_2.png) [@k3KAW8Pnf7mkmdSMPHz2](https://discourse.jabref.org/u/k3KAW8Pnf7mkmdSMPHz2)\
**Post date:** [July 14, 2021, 6:55pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/12 "2021-07-14T18:55:55Z")

</div>

Not sure enough about JavaFX to tell you what is going on there 😛  
That is the full error message?

I think your original issue might come from a mistake in how the directory name is checked. If the file is in the root of your file directory it is always considered to be in the right place (which is why the action to move it is grayed out).  
I am less sure why your workaround works though 😛

---

<div class="post-metadata">

**Author:** ![k3KAW8Pnf7mkmdSMPHz2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/k3kaw8pnf7mkmdsmphz2/32/1116_2.png) [@k3KAW8Pnf7mkmdSMPHz2](https://discourse.jabref.org/u/k3KAW8Pnf7mkmdSMPHz2)\
**Post date:** [July 14, 2021, 7:41pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/13 "2021-07-14T19:41:00Z")

</div>

I added [#7908](https://github.com/JabRef/jabref/issues/7908) on GitHub.

Just one last thing, the [cleanup action](https://docs.jabref.org/finding-sorting-and-cleaning-entries/cleanupentries) does not work either? With the `Move files to default file directory`, (same as christoph)

---

<div class="post-metadata">

**Author:** ![Siedlerchr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/siedlerchr/32/216_2.png) [@Siedlerchr](https://discourse.jabref.org/u/Siedlerchr)\
**Post date:** [July 14, 2021, 7:56pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/14 "2021-07-14T19:56:13Z")

</div>

Regarding drag and drop, JabRef uses modifier keys, but there is a bug in java/javafx [https://bugs.openjdk.java.net/browse/JDK-8264172](https://bugs.openjdk.java.net/browse/JDK-8264172)

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 14, 2021, 9:08pm UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/15 "2021-07-14T21:08:28Z")

</div>

Thanks for creating the issue!

Also, the cleanup action works perfectly. Pressing a hotkey once is much, much more convenient than the tedious workaround I found, so it’s the best solution until the drag&drop bug is fixed, I guess.

* * *

Another question as I have experimented a bit with renaming patterns: is it somehow possible to make certain characters only appear when a expression is present? In case of my renaming pattern  
`[authEtAl]_[year]_[title]_[firstpage]-[lastpage]`  
there are instances where there is aren’t first and last pages (e.g., a monography). In that case, Jabref still appends the `_-` which is unnecessary when there without the page information. It results in something like this:  
`PassothEtAl_2012_Agency without Actors_ New Approaches to Collective Action_-.pdf`

Is it possible to prevent the `_-` from occurring when there are no page numbers?

---

<div class="post-metadata">

**Author:** ![k3KAW8Pnf7mkmdSMPHz2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/k3kaw8pnf7mkmdsmphz2/32/1116_2.png) [@k3KAW8Pnf7mkmdSMPHz2](https://discourse.jabref.org/u/k3KAW8Pnf7mkmdSMPHz2)\
**Post date:** [July 15, 2021, 1:52am UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/16 "2021-07-15T01:52:16Z")

</div>

Not really, no. You can work around it like this, which should work in most circumstances. I had a lot of issues actually saving the pattern. Not sure what went on there

```auto
[authEtAl]_[year]_[title][firstpage:regex(".+", "_$0")][lastpage:regex(".+", "-$0")]

```

---

<div class="post-metadata">

**Author:** ![armenaton](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@armenaton](https://discourse.jabref.org/u/armenaton)\
**Post date:** [July 15, 2021, 11:36am UTC](https://discourse.jabref.org/t/how-to-use-file-directory-pattern/2802/17 "2021-07-15T11:36:55Z")

</div>

works perfectly for me, thanks! 🙂
