Copy link to clipboard
Copied
I have a script that writes a PDF to the user's desktop, then calls a VB script to attach the PDF to a Slack post. Most of the time it works just fine but occasionally the saved PDF is a zero-length file that Slack can't handle. My inclincation is to add some logic to check file.length before proceeding, but I'm not what to do if/when the file.length is zero. Pause for a few ticks and try again?
Hoping someone else has encountered something like this.
Bob
Copy link to clipboard
Copied
Hello Bob,
Check out all three answers on this post to see if they'll help you out.
https://stackoverflow.com/questions/7161739/how-can-i-check-if-a-file-exists
Regards,
Mike
Copy link to clipboard
Copied
It's not a file.exists problem. The file exists but, once in a while, file.length is zero
Slack won't accept that, understandably.
I'm trying to use $.sleep to build in a short pause between executing fileExport and starting the Slack upload process. But I'm not clear on one important question: Does pause the script execution also pause the fileExport process? I wouldn't think so but I just don't know.
Copy link to clipboard
Copied
hi Bob,
Here's a post to check to see if the file size has changed.....maybe you can do the upload when the file size has stopped changing.
if you're doing the file export and move is the same script you could try asynchronousExportFile, and use waitForTask(); before the upload process starts.
below is an example copyied from one of my scripts.
task = doc.asynchronousExportFile(ExportFormat.PDF_TYPE, File(myFolder +'/'+ my_layer + mySuffix + "HR.pdf"), false, export_preset4);
task.waitForTask();
//Do your upload after the export has completed.
Regards,
Mike