I have a folder full of PDF files that is continuously updated with new PDF files throughout the day (all are named randomly). I currently open the PDF file and do a File → Save As... naming it with a different name. Is it possible to delete the original file that was opened after doing a File → Save As...?
My current practice is to open the randomly named PDF file, do a File → Save As... (based on info contained in the PDF) and then deleting the randomly named file.
So file name is EFAXB1_2107221804310250.pdf. I open the file and do a Save As so now I have the new recently named file and the original PDF file. It would be awesome to automatically delete the previous file.
Delete original PDF when doing a File → Save As
Re: Delete original PDF when doing a File → Save As
Code: Select all
dir := A_ScriptDir, control := "Edit1"
#IfWinActive ahk_exe Acrobat.exe
F12::
InputBox, new, New file name, Enter a new file name.,, 300, 125
If (ErrorLevel || new = "")
Return
Send ^+s ; Save as...
WinWaitActive, Save As PDF ahk_class #32770 ahk_exe Acrobat.exe,, 40
If ErrorLevel {
MsgBox, 48, Error, An error occurred while waiting for the window. Aborting.
Return
} Else Sleep, 1000
ControlGetText, old, %control%
Control, EditPaste, %new%, %control%
Send `n
Sleep, 1000
If FileExist(dir "\" new ".pdf")
FileRecycle, %dir%\%old%
Else MsgBox, 48, Error, The new file was not found.`n`n%new%.pdf
SoundBeep, 1500
Return
#IfWinActive
Re: Delete original PDF when doing a File → Save As
This is awesome and I appreciate your time spent.
Currently, the script prompts me for the new file name. I enter the new name, the save as dialogue appears and it is saved out with the new name. However, the old file is not deleted.
The only thing I changed in the script is the directory. Any ideas?
Currently, the script prompts me for the new file name. I enter the new name, the save as dialogue appears and it is saved out with the new name. However, the old file is not deleted.
The only thing I changed in the script is the directory. Any ideas?
Re: Delete original PDF when doing a File → Save As
If you do not see the message box about "file was not found", then it means that the file path is wrong, or perhaps the file is open by another program at the same time, or perhaps you do not have access rights to delete the file. Identifying the problem should be straightforward by examining these possibilities. You can try running the script as admin if access rights seems that it might be one of the possibilities. You can also have the script display the file path to ensure that it is correct. You can add a new line to display whether the file exists. You might also try increasing the final sleep. If you are trying to delete the old file while Adobe is still accessing it, the deletion might fail, so this is why increasing the final sleep might be needed. Among all of the possibilities, my guess would be that the final sleep is currently too short.
Who is online
Users browsing this forum: roysubs and 281 guests