0

I am trying to read a file in my Download folder (I have a mac system) using the below line of code:

    PDDocument doc = PDDocument.load(new File("/Users/mohand/Downloads/1963_Automation_BigTurnip_290618.pdf"));

The problem is, the numeral "1963" will keep on changing but text "_Automation_BigTurnip_290618.pdf" will remain the same.

Can I use any regex that will pick up any file that has "_Automation_BigTurnip_290618.pdf" ?

1

3 Answers 3

1

I did this using :

File dir = new File("/Users/mohand/Downloads/");
File[] files = dir.listFiles((dir1, name) ->  name.endsWith("Automation_BigTurnip_290618.pdf"));
Sign up to request clarification or add additional context in comments.

Comments

0

No need for regex. Just use endsWith:

if (name.endsWith("_Automation_BigTurnip_290618.pdf"))

2 Comments

How do i use this in my path name?
@moh17 Your question is how to do a regex pattern to match file names. I've suggested not to use regex for that. If you really wanted to ask how to scan files in a directory, then you should edit the question and clarify that that is what you need to know. This answer is for the question as it is currently written, i.e. just about name matching.
0

You could use a regular expression like this:

^(\d+)_Automation_BigTurnip_290618\.pdf$

This would match any file starting with at least one digit and ending in the pattern you specified.

2 Comments

How do I use this inside my path name as given in the OP?
@moh17 The path name given in the OP is a hardcoded string, so you don't need a regular expression. Your question makes no sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.