Managing attachments in confluence
Asked by Jayesh Baviskar:

Hi,

I am looking to delete multiple attachments on a confluence page. The page was initially created using a copy of an exisiting page. In this process, the attachments from the previous page were carried over to the new page. Im now looking at a list of about 200 attachments. Based on this, Im looking for an effective approach to identify and delete the attachments that are not linked to the front-end of the page (only to looking to identify the attachments that are not in use on the page and to delete these).

Could anybody suggest a way to identify the documents that are currently in use/linked on the page vs the attachments that are not in use on the page (one's that are simply piled on to the page located on the back-end). And, is there a way for me to get an indication of the not-in-use attachments in the 'Attachments' window of the page? Please advise.

Thank you.


Answers:
author: Grigory Salnikov
body: Hi, [@Jayesh Baviskar](/t5/user/viewprofilepage/user-id/645658)!

I think I may have the answer.

1. You need to view the "Storage Format":

![storage format.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/30749iDF7C9EB66443B47D/image-size/large?v=v2&px=999 "storage format.jpg")

2. Find (or even grep) the word **"filename="** and there will be the attachments which is used on the page. The number of occurrences equals the number of 'active' attachments.

I tested it in my environment and it works.

Hope this helps.

comments: author: Jayesh Baviskar
body: Hi [@Grigory Salnikov](/t5/user/viewprofilepage/user-id/1323725)

Thanks a ton. This information is super helpful for me.

To confirm again; Is it correct to understand that if i view the storage format, extract all results associated with the word "filename=", I would be looking at a list of all the active attachments that are currently linked on the page? This is really good information.

However, I'm also in a fix now. I have a set of 70 pages that require cleaning up of dead attachments. Based on what we discussed, I will need to extract results for each page, retain the resulting attachments on the confluence page, and delete the dead one's (those that don't reflect as part of "filename="). Could you recommend an alternate way to approach this? Some way that would be less time consuming considering the count of 70 target pages... (I'll follow what you suggested in case we don't have an alternate approach for this)

A big thank you again for the prompt response.


author: Grigory Salnikov
body: Hi!

Yes, I've tested the behaviour, and it seems ok - the result equals all the 'active' attachments on the page. You can verify it in your environment (I think it's better to).

To reduce the amount of time to be spent on this task I can recommend you the following regular expression:

```
filename="([^"]|\n)*"
```

You can either use Notepad++:

![regex.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/30767iA45E5C6E6C80AA1F/image-size/large?v=v2&px=999 "regex.jpg")

Or using Linux terminal:

```
egrep -o 'filename="([^"]|\n)*"' <file_with_saved_text_from_storage_view>
```

to extract filenames only you can add:

```
egrep -o 'filename="([^"]|\n)*"' <file_with_saved_text_from_storage_view> | cut -f2 -d'"'
```

Hope this helps.


author: Grigory Salnikov
body: I'm not sure whether it's possible to automate the process even more.

As an alternative way, I can also recommend you this:

[Use a WebDAV Client to Work with Pages](https://confluence.atlassian.com/doc/use-a-webdav-client-to-work-with-pages-200704169.html)

I haven't used it myself, though, and can't share any practical advice.

It's a powerful tool for sure :)

... and worth taking a look.


author: Grigory Salnikov
body: Hi, [@Jayesh Baviskar](/t5/user/viewprofilepage/user-id/645658)!

How is your task? Have you managed to accomplish it?


author: Jayesh Baviskar
body: Hi [@Grigory Salnikov](/t5/user/viewprofilepage/user-id/1323725),

I tested suggestion provided by you and it worked for me.

Thank you very much.


author: Grigory Salnikov
body: Hello, [@Jayesh Baviskar](/t5/user/viewprofilepage/user-id/645658)!

Glad it worked! You're always welcome!

Have a nice day :)