# Date pattern in file input path

**URL:** <https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538>\
**Category:** Logstash\
**Created:** [September 14, 2017, 12:55pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538 "2017-09-14T12:55:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shashwat](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@shashwat](https://discuss.elastic.co/u/shashwat)\
**Post date:** [September 14, 2017, 12:55pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/1 "2017-09-14T12:55:56Z")

</div>

Hi,

I am in need to read files from different folders. These folders are maintained daily in the format of dates. e.g. 20170912, 20170911 etc.

I am trying the file input path as "var/opt/data/%{+YYYY}%{+MM}%{+dd}/\*.txt" but it is not working.  
How can I read files in such a case?

Thanks,

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 14, 2017, 1:08pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/2 "2017-09-14T13:08:00Z")

</div>

There's no automatic way of selecting "file of the day". Can't you just use a wildcard and have Logstash read all files as soon as they become available?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 14, 2017, 1:44pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/3 "2017-09-14T13:44:19Z")

</div>

Depending on your platform you might be able to set an environment variable to the name and then reference that in the config. For example, I have a nightly job that processes the prior day index. In the script that runs I set

> ```
> INDEXDATE=`date --date="-1 day" '+%Y.%m.%d'`
> ```

and in the logstash configuration I have an elasticsearch input that reads

> index =\> "logstash-${INDEXDATE}"

---

<div class="post-metadata">

**Author:** ![shashwat](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@shashwat](https://discuss.elastic.co/u/shashwat)\
**Post date:** [September 14, 2017, 2:01pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/4 "2017-09-14T14:01:57Z")

</div>

> [@magnusbaeck](#):
>
> There's no automatic way of selecting "file of the day". Can't you just use a wildcard and have Logstash read all files as soon as they become available?

Actually , there are other files/folders also in that directory besides these date formatted folders. I do not want to process all that data. I just need to target these date specific folders. For wildcard , either I give something like /var/opt/data/2017\*/\*.txt . Can you please suggest any better way?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 14, 2017, 4:03pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/5 "2017-09-14T16:03:38Z")

</div>

If you can find a wildcard that matches the files you want to capture and nothing else I'd say go for it. Otherwise you'll have to periodically generate a configuration file with specific paths or use @Badger's solution with an environment variable.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2017, 4:03pm UTC](https://discuss.elastic.co/t/date-pattern-in-file-input-path/100538/6 "2017-10-12T16:03:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
