Button that Gets Created/Modified Date for Multiple Files From txt File

Hi everyone!

I'll start by posting the button I've done so far, then explain what it is I'd like it to do, to see if someone can help.

@set publishdate={dlgstring|Enter publishing date (YYYYMMDD):|}
SetAttr META "createdate:{$publishdate} 00:00:00"
SetAttr META "lastmodifieddate:{$publishdate} 00:00:00"
Select NEXT 

This will set the Creation Date and the Last Modified Date of a single selected file to 12 AM on the date specified in the dialog box before moving on to the next file and stopping. This works as expected, but is not exactly what I want.

Basically, I have 19 files in a directory: 18 files with a .zip extension, and a txt file called "PublishingDates.txt"

The text file lists the dates like so:


Instead of selecting each file individually and having me type in the publishing date into a dialog one by one, what I'd like my button to do is once I've selected all the files I want to modify the dates of, I can run the button and have it be able to pull the values createdate and lastmodifieddate from each line of the text file, along with a default time of 00:00:00 and apply the info from the first line to the first selected file, the info from the second line to the second file, and so on.

For example, I would select two of the zip files in the folder and it would grab the date info for them from the first two lines of PublishingDates.txt as such:

Creation Date: May 17, 2004 12:00:00 AM
Last Modified Date: May 17, 2004 12:00:00 AM

Creation Date: July 15, 2004 12:00:00 AM
Last Modified Date: July 15, 2004 12:00:00 AM

Is there a way to do this, as my button works fine as is for small amounts of zip files, but I want to make it be automatic, since the next series of books I want to do has 94 volumes and is way too tedious, time consuming, and prone to errors if typed in dialog boxes manually one by one.

That command will/should actually set the dates on all selected files to the one you specify. If you don't give the SetAttr command an explicit file path, it will apply the requested change to all selected files automatically.

The Select NEXT part is not needed at all.

You can also make things more efficient by setting both timestamps at once:

@set publishdate={dlgstring|Enter publishing date (YYYYMMDD):|}
SetAttr META "createdate:{$publishdate} 00:00:00" "lastmodifieddate:{$publishdate} 00:00:00"

You could do that using Scripting. It would need script code to be able to read in a text file, turn it into an in-memory table of filenames and corresponding dates, and apply them to each file. The script would probably not be too complicated, but you couldn't do that kind of thing without scripting.

If you link your account we can help write the script, if needed.

Thank you, Leo. I didn't know the SetAttr function could modify 2 pieces of metadata in the same line.
I made what I had for my button based on pieces I found by searching through the archives in this forum, and the few pieces I could figure out on my own.

As you said, I found that the function did set the dates on all selected files to the one I specified. However, this was not what I wanted, because each ebook zip file was published on a different date. So instead, I tried solving it by simply selecting the first file I want to change the date stamp of, and having the button get the date from the user through a dialog box, apply that date to the selected file, and move on to the next file with the Select NEXT command. I then wanted it to auto-repeat the process from the beginning with the newly selected next file, getting a new date from another dialog box, etc, and keep auto-repeating that process until it either reached the end of the list of files (in which I assumed Select NEXT would no longer work) or until I pushed cancel on one of the dialog boxes.

However, I found a post (probably from you) made several years ago that said DOpus doesn't have such a repeat function, so the Select NEXT in my button did indeed, end up being unnecessary.

That is why I wanted to change my approach to grabbing the dates from a list in a txt file, since doing so would allow the button to apply unique dates to all the files, as well as eliminate having dialog box after dialog box pop up.

However, I am completely unfamiliar with scripting, and would greatly appreciate any help you can give in writing the kind of script you mentioned.

I have just linked my account on this forum to my license, so I thank you in advance for your help.

Is the text file something you will have already, or is that just a way for you to enter the dates for all the files at one?

i.e. Would you be typing the text file by hand each time before running the button? If so, would you prefer to just be prompted once for each file, and not have to make the text file?

Where does the text file come from? Will it always match the number of files, with the filenames sorted in alphabetical order (according to your current locale)? It seems a strange way to transport the file dates, as just a list of dates with no names next to them. A script can work with that, but it makes me wonder if the source of the data is the text file, or if the text file is an intermediate step that we might be able to replace with something better.

The text file is, as you said, an intermediate step. It's something I made when I found that I couldn't get the process in my original button to repeat automatically. I had to manually make the text file by typing the dates in the format DOpus requires based on information from Wikipedia. The wiki said, "Volume 1 Publish Date: May 17, 2004. Volume 2 Publish Date: July 15, 2004..." so I typed the dates as 20040517, 20040715, etc. as a list in notepad and saved the text file in the same directory as the e-book zip files.

To answer your other questions, the filenames will always be sorted in alphabetical order, but the text file may not always match the number of files. For example: for e-books in an ongoing series, I may do volumes 1-20 now, and volumes 21-30 after they are released and I've added them to the same folder as the previous 20.

When I consider all of that, it would probably be better to not have to make the text file in the first place, and find some better way to do it. Maybe being prompted for each file?

In that case, I think this is all you need:

dopusrt /cmd SetAttr FILE {filepath$} MODIFIED="{dlgstring|Enter publishing date (YYYYMMDD):} 00:00:00" CREATED=modified

The dopusrt /cmd part is a trick to make Opus run the command as if it was an external command, re-parsing the command line for each file, and ensuring the SetAttr command only sees one file at a time.

1 Like

Wow, that works great! And everything's in a single line :open_mouth:
Thank you so much for figuring that out for me.:smiley: I'll have to look into what you said about using dopusrt and the /cmd part, since it looks like that will be useful in the future.

Even though this does work perfectly, I am curious as to how to do it by parsing a text file if I ever needed to. I know that, a long time ago, someone posted a rename script on this forum that grabs filenames from a txt file and applies them to the selected files, which is why I had thought that the same thing could be done on a button with a file's metadata...

Don't worry too much about that part. It's a little arcane and not needed that often (at least these days; it was needed more often in the past). Still useful occasionally but not worth losing sleep over!