1.

Solve : Need help with finding a string in a file and then . . .?

Answer»

Our translation software translates a file and then writes it to a specific folder.  The batch file I'm writing needs to rename the file, but first, needs to determine if the file translation is finished before I try to do anything else, so, I need to first loop through the first file in a folder, look for the string 'end of file'.
If it finds 'end of file', then continue on with the rest of the code
else
try two more times to find the 'end of file' and if it doesn't find it, then move the file to an error folder and go to the next file.

The translations only takes seconds, but we've had issues in the past where every once in a while, the timing will be so that the batch file call will be just before the file gets finished translating, and cause problems.

Thanks for any help you can provide.

Jeanette
The translation software should have the file "open" and therefore unable to edit when it is writing to it. Is this statement not true in this case? If so, why?

An easy check would be to see if the file is indeed "open" and then act depending on ERRORLEVEL. Here's a simple construct of the test. It WORKS because you are not able to rename a file if it is being edited by another process.

Code: [Select]:loop
ren %filename1% %filename2%
if errorlevel 1 (
  ping 1.1.1.1 -n 1 -w 2000>nul
  goto loop
) else ren %filename2% %filename1%

You can also use some coding using the tasklist command to check and see if the translation task is still running. I'll see if I can find the old post that shows a good code on how to do that.
Quote from: Raven19528 on November 23, 2011, 01:04:22 PM

The translation software should have the file "open" and therefore unable to edit when it is writing to it. Is this statement not true in this case? If so, why?
Whether a file is open has no bearing whatsoever on whether the file can be CHANGED. That depends on the dwShareMode parameter that was used when the file was opened, which is usually as lax as possible. In this case the ShareMode would have to include FILE_SHARE_DELETE to allow renaming the file.

In any case, my point is that whether a file is open is entirely separate from whether it can be opened, read, written, renamed, or deleted. Quote from: BC_Programmer on November 23, 2011, 02:04:15 PM
In any case, my point is that whether a file is open is entirely separate from whether it can be opened, read, written, renamed, or deleted.

Right. Again, BRAIN too involved with visions of turkey INDUCED coma in very near future.

In any case, this post shows how to use the tasklist command to see if a program is running. It may provide a more accurate assessment of whether the translator program is running or not.


Discussion

No Comment Found