Getting filepath of last created file doesn't work

Hi guys,

I have the following problem:

The formula works in the sense that it finds the latest file and it gives me the filepath. But, there is a small mistake in the filepath which makes that it doesn’t work.

Result:
“C:\Users\Tvanhaperen\AppData\Local\Temp\Olympus~$e43d8f-9107-4620-b825-1a95b9224b7b.doc”
Result as it SHOULD be:
“C:\Users\Tvanhaperen\AppData\Local\Temp\Olympus\3Ce43d8f-9107-4620-b825-1a95b9224b7b.doc”

As you can see, the first 2 characters of the filename are replaced by “~$”. This happens with xlsx, docx and ppt files. Pdf files on the other hand do not show this problem.

In the next activity, I use this filepath to copy the file to a new location. Right now, this results in a corrupted file.

Does anybody have an idea how to fix this? :smiley:

Regards, Ties

Hello @Ties

According to Microsoft documentation, that squiggly mark followed by the dollar sign indicates a currently open file:

The files you are describing are so-called owner files (sometimes referred to as “lock” files). An owner file is created when you work with a document in Word, and it should be deleted when you save your document and exit Word.

Try closing all open instances of Word and run the formula again, it should work.

Regards,
Alan C.

Ill share my solution later Today :slight_smile:

String.Join(“”, Directory.GetFiles(YourFolderPath,“*.xlsx”,SearchOption.TopDirectoryOnly).Where(Function(f) Not path.GetFileName(f).StartsWith(“~$M”)).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(2))

Good luck :slight_smile:
I have only tested this on .xlsx files - but im sure it works for all :slight_smile:

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