Best answer

Increment file name if file exists


Userlevel 1

Hi all,

I’m using Zapier to store PDFs that are generated by Gravity Forms and Gravity PDF.

The Zap I have set up checks to see that the correct folder and subfolders exist and then uploads the PDF.

All good so far.

Is there a way I can check to see if the file name already exists and if so append or increment the file name as the same user will complete the form several times and we want to be able to see at a glance from the file name what the order of submission was.

For example:

  • Submission 1 uploads the PDF with the original file name - John Smith-FrenchLesson101.pdf
  • Submission 2 uploads the PDF with the original file name + 1 John Smith-FrenchLesson101-01.pdf
  • Submission 3 uploads the PDF with the original file name + 1 John Smith-FrenchLesson101-02.pdf
  • Submission 4 uploads the PDF with the original file name + 1 John Smith-FrenchLesson101-02.pdf

and so on

Thanks

icon

Best answer by christina.d 13 July 2022, 23:58

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

8 replies

Userlevel 7
Badge +14

Hi @philthebass 

Good question.

Here’s the issue to consider…

If there already exist multiple Files in the GDrive that have a similar name, then the GDrive Find File Zap action (see below) may not return the highest named file.

For example, it may return the first file found, the last file found, the most recently updated file found, etc.


My suggestion to keep this simple would be to append a UNIX timestamp, which will always be unique and incrementing, to the end of the file name.

 

This serves 3 purposes:

  1. Makes file names unique
  2. Makes files auto sort correctly
  3. Makes files traceable as to when they were first generated/uploaded

 

Insert the time your Zap runs into a field

Help article: https://zapier.com/help/create/customize/insert-the-time-your-zap-runs-into-a-field

 

{{zap_meta_timestamp}}

This timestamp displays UNIX time.
Example: 1656689630 [Seconds since Jan 01 1970. (UTC)]

 

Unix time is a system for describing a point in time.
It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds.
The Unix epoch is 00:00:00 UTC on 1 January 1970.

 

Similarly, you can use the Jotform Entry ID returned from the Zap trigger step to make file names unique and ordered.

Userlevel 1

Hi Troy,

We timestamp the PDF when it’s generated, but the client struggles to read the time stamps, so we’re trying to figure out a way of simplifying the file names appended with 01 02 03 etc.

I think you’re right, there’s no real way of doing that.

I was hoping that Google Drive would allow us to append file names for duplicates (like Mac OS and WIndows does) with (01) (02) etc. but that’s not available as a feature.

I think we’ll have to write some custom code for Gravity forms that counts the number of submissions per user and then appends the file name accordingly.

Thanks again

Phil

Userlevel 7
Badge +14

@philthebass 

There are more advanced ways to achieve this.

e.g. You can log files into an Airtable Base and use that to determine how many of a current file name exist to then get the unique # value to append before upload to GDrive.

Userlevel 4
Badge +5

Hey, @philthebass 

Troy had some great suggestions for dealing with finding the latest file. If you want to auto-increment increment a number, you can use the Storage by Zapier app.

 

Here’s a basic primer on Storage: https://zapier.com/help/create/storage-and-digests/save-and-retrieve-data-from-zaps

And here’s some use cases, including how to auto-increment: https://zapier.com/help/create/storage-and-digests/storage-examples-in-zaps

 

I hope this points you in the right direction! Please let me know if you have any other questions.

Userlevel 1

Thanks @MichelleS - I’ll check that out

Userlevel 7
Badge +9

Hi there, I wanted to swing by and summarize some of the awesome suggestions here!

 

If there already exist multiple Files in the GDrive that have a similar name, then the GDrive Find File Zap action (see below) may not return the highest named file.

For example, it may return the first file found, the last file found, the most recently updated file found, etc.


My suggestion to keep this simple would be to append a UNIX timestamp, which will always be unique and incrementing, to the end of the file name.

 

This serves 3 purposes:

  1. Makes file names unique
  2. Makes files auto sort correctly
  3. Makes files traceable as to when they were first generated/uploaded

 

Insert the time your Zap runs into a field

Help article: https://zapier.com/help/create/customize/insert-the-time-your-zap-runs-into-a-field

 

{{zap_meta_timestamp}}

This timestamp displays UNIX time.
Example: 1656689630 [Seconds since Jan 01 1970. (UTC)]

 

Unix time is a system for describing a point in time.
It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds.
The Unix epoch is 00:00:00 UTC on 1 January 1970.

 

Similarly, you can use the Jotform Entry ID returned from the Zap trigger step to make file names unique and ordered.

Michelle also had some great insight to share here: 

 

Troy had some great suggestions for dealing with finding the latest file. If you want to auto-increment increment a number, you can use the Storage by Zapier app.

 

Here’s a basic primer on Storage: https://zapier.com/help/create/storage-and-digests/save-and-retrieve-data-from-zaps

And here’s some use cases, including how to auto-increment: https://zapier.com/help/create/storage-and-digests/storage-examples-in-zaps

 

I hope this points you in the right direction! Please let me know if you have any other questions.

 

Userlevel 1

Thanks @christina.d  - we’ve decided to include the time stamp in the filename for the PDF that is generated by Gravity PDF which should do the trick.

We’re testing it with the client at the moment and will more than likely set it up in production next month.

Userlevel 7
Badge +9

Amazing, @philthebass! Thanks for keep the thread updated with your solution! Love to see it. 🤗