Can DOS close an open file?

I'm trying to setup a cron job for my brother that goes out to the web and retrieves an excel file and overwrites the existing copy on his desktop. The problem I'm facing is I have to kill the process (excel.exe) if the file is open while the batch file runs, otherwise, it will create another copy with a 1 or 2 or 3, etc appended to the end of the filename. For example, the correct filename would be myfile.xls and it will create myfile.xls(1). So, I kill the process before it goes out to the web to retrieve the file. This works, but ideally, I would like to close that particular file without killing the process in the event he has other files in open state . . . is this possible?

Not easily and not directly through DOS. You would have to write a control for excel to close and reopen the file.

You might try the following:

The cron job first retrieves the file and saves it locally under a unique name. Then it runs a loop which terminates as soon as the excel.exe process goes away and then moves the file to the final destination. In pseudocode:

get_file_from_internet()
save_file( "some_unique_name" )
while ( excel.exe is running ) {
     wait()
}

move_file( "some_unique_name", "myfile.xls" )
end()

Depending on the frequency of how often the cron job runs and how often it gets a new version of the file you might have to implement some sort of locking mechanism because a cron job could already be waiting to replace the file when the next one starts and retrieves an even newer version of the file.

I hope this helps.

bakunin