cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
james_goodhew
Advocate III
Advocate III

Remove characters after 5 digit project number in filename

 

I need to strip everything off the PDF Name after the 5 digit project number, and use that information as the destination for a Move File action.

 

All project folder names have this structure: PROJECTNAME - 12345

PROJECTNAME has no requirements except less than ~30 characters, and no disallowed characters.

The suffix to end the folder name is SPACE HYPHEN SPACE 5DIGITS (always, this is coded*).

 

What I need to do in Flow is move the PDF of the drawing to its project folder.

The PDF Name is of the format PROJECTNAME - 12345-LAYOUTNAME.pdf

The PDF source location is always the same, and all files created in that location need to be moved.

The destination folder is always Y:\02 Projects\PROJECTNAME - 12345

 

I've initialized variables like:

RequiredLength as Integer, Initial Value 5.

InputText as String, Initial Value 'File Name' (from Dynamic Data)

CharacterList as Array, InitialValue IDONTKNOW


I did find the following from this link, but don't know how to translate the rest into Flow actions:

 

(InputText as text) =>
let
RequiredLength = 5,
Digits = {"0".."9"},
CharacterList = Text.ToList(InputText),
FirstNumber =
List.Accumulate(
CharacterList,
"",
(String,CurrentChar)=>
if Text.Length(String) = RequiredLength then String
else if List.Contains(Digits,CurrentChar) then String & CurrentChar
else ""
) ,
ReturnValue =
if Text.Length(FirstNumber) = RequiredLength then FirstNumber else null
in
ReturnValue

 

 

*until we hit the millennium bug and need a 6th digit

** My first post was marked as spam and hasn't come back online, so sorry to repeat but I'd love an answer if anyone out there can help 🙂

13 REPLIES 13
abm
Super User
Super User

Hi @james_goodhew 

 

You can use the split expression function to split the PDF  file name.

 

If you need any further help in this please let me know.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
abm
Super User
Super User

Hi @james_goodhew 

 

Please follow these steps:

image.png

 

The expression I used above is as follows:

split(variables('PDFFileName'), '-')
concat(outputs('Compose_2')[0], ' - ' ,outputs('Compose_2')[1])
 
If you need any help in this please let me know.
 
Thanks


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hello @abm 

Thank you so much!

Now I have one small challenge: Output of the second Compose has an extra " " character both sides of the " - " separator, so the folder path is incorrect. Any idea why that might be?

I used a Replace function to replace '  ' with ' ' and it works now, but would be nice to clean up if possible.

 

[Edit] I realised I had to use the Expression builder: click into the field, dynamic content pops up to the right. Next to the heading of that box is another available heading 'Expression'. Click 'See More' under String Expressions section and you will find Split and Concat functions. Below is now irrelevant.

Unfortunately, I get error in the body of my Move: Cannot verify existence of destination at

'SITEADDRESS/02 Projects/Projects/concat(split(TESTJG - 12345.pdf, '-')[0], ' - ',split(TESTJG - 12345.pdf, '-')[1])'
I don't think the expressions are evaluating, because the outputs of each Compose match the inputs of the same Compose...?

Hi @james_goodhew 

 

Thanks for your reply. 

 

To remove the space between ' - ' you can change the expression under the concat to '-'.

 

Please see below.

concat(outputs('Compose_2')[0], '-' ,outputs('Compose_2')[1])

 

Try this and let me know

 

Thanks

 

 

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hello @abm , I can't do that sadly because our users are allowed to use '-' characters elsewhere in the project name. ' - ' is banned from use, because it's our delimiter for project number.

I'll stick with the replace() for now.

There will be a challenge if a user uses '-' elsewhere in the filename though... That's why I asked about finding the 5 digit number initially.

Hi @james_goodhew 

 

Thats fine. You still having issues with the SharePoint path not found error? 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hi @abm , no the path is correct now, as long as there is no hyphen in the project name. I don't want to mark your answer as the solution, because (although very clever) the ultimate answer to the question is to find the 5 digit number and strip its suffix.

Hi @james_goodhew 

 

Thanks for your quick reply.

 

Lets try to understand this. So you have the following filename.

PROJECTNAME - 12345-LAYOUTNAME.pdf

Here you need to get the numeric value only and strip everything else?

 

First step is remove the spaces. Here you could use replace expression with space with ''.

This will result the filename as follows:

PROJECTNAME-12345-LAYOUTNAME.pdf

 

Next use the split function to split the projectname,numeric values & layoutname using '-'

From the split output index 1 should get the numeric value you want.

 

Thanks

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

No that's not it. The ' - ' and the 5 digit number are the only valid delimiters.

The hyphen itself is not really useful because PROJECTNAME can contain a hyphen anywhere.

 

To give an explicit example:

I need to move file: P-R-O-J-E-C-TNAME - 12345-LAYOUTNAME.pdf

to destination:         P-R-O-J-E-C-TNAME - 12345

 

One possibility is there are always only 5 digits to keep after the ' - ' delimiter, so if we can do the split and say take the length of the split, add 5, and take that from the original filename, we have a valid path..?

If you can split starting from [character where ' - ' ends + 5] (I think), then we are onto a winner.

Hi @james_goodhew 

 

It is possible but we need to do quite a lot of string manipulations to extract the numeric and other strings.

 

Try the following.

 

Find the total length of the string.

Find the last hyphen position and previous using a Do until loop by reading each value from the filename. Before the Do until declare two values as integer. Use these two integer variables (swap the values until the loop process ends) for storing the hyphen positions. Once you find the position of last and previous value of hyphen you could use the substring() function to extract the values.

 

Thanks

 

Thanks 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hello @abm , thanks for the deep suggestion - but I just used your logic and stretched it out:

 

Split(PDFFILENAME,' - ')

Length(Output) under Collections on the output

Add(output,3) to add characters for the ' - ' I want to keep

Add(Output,DigitsInProjectNumber) to add characters for the project number (for now always 5 but I can change the variable value when we get to that point).

substr(PDFFileName,0,Output) to get the desired folder path.

 

Finally nailed it for what I need, although there is no flow logic currently to find a project number of defined length within a string...

Thank you so much for opening my eyes to alternative possibilities!

v-alzhan-msft
Community Support
Community Support

Hi @james_goodhew ,

 

The link below could help you:

https://powerusers.microsoft.com/t5/Building-Flows/Split-Extract-names-from-a-delimiter-string-in-Fl...

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you, but my specific question is how to use a number of n digits as a delimiter. Perhaps I should pose this as a separate question, but it's academic now I have a solution involving the " - " delimiter and adding the requisite n to the length, as above. I won't mark it as a solution because it doesn't solve the question about using a number of n digits as a delimiter.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,293)