Detecting end of processing?

Started by terrypin, March 24, 2013, 02:39:44 PM

Previous topic - Next topic

terrypin

I'm developing a series of macro scripts to execute various commands. So far these include
1. Write Comments.TXT for folder
2. Write Comments-All.TXT for folder + subfolders
3. Write separate Comments.TXT for all subfolders

In each case, at the end of processing the ExifTool command I want to close the Command Prompt window (which was opened automatically by the macro).

I achieved this somewhat obscurely for 1 and 2 (by testing when the file's length was > 0) but that approach obnviously doesn't work for 3 because the text files are in  subfolders.

Is there a programmatic way of telling when CMD.EXR has done its stuff please?

--
Terry, East Grinstead, UK

terrypin

Doesn't seem possible to Edit that?

The last sentence should read:
'Is there a way of telling when ExifTool has done its stuff please, so that I can get my macro to close the Command Prompt? Or alternatively can I get it to close automatically when it's finished?'

--
Terry, East Grinstead, UK

Tarn

Hi Terry,

I'm not sure (read have no idea) about your EXR script; but for batch files, the "exit" command will abort the batch file and close the command window. In short, putting "exit" on the last line will close the window.

Not sure if that gives you an idea of which direction to go, or not.

terrypin

Hi Tarn,

Thanks, that could turn out to be a simple solution for the batch file approach.

I'm getting back into those very shortly. The major difficulty is that I want to automate the process, as I need to apply these commands to hundreds of folders. So typically I'll have an Explorer folder open, browsing and viewing its files etc, and I'll want to prepare a Comments.txt file using the appropriate ExifTool command. So my macro must first create the correct batch file, incorporating the folder path and name, and then run it.

Frankly, I could well end up setting aside my aversion to working in the Command Prompt, drop my macros and batch files, and simply use the drag 'n drop method!

--
Terry, East Grinstead, UK

Phil Harvey

I haven't responded because I don't know the answer to the question, but I just wanted to be sure you're not using the -k option.  Without this option, it must be something else other than ExifTool keeping the window open.  I think there may also be ways to launch ExifTool from batch without opening a window to begin with, but I don't know them myself.  Did you try searching in here?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

terrypin

#5
Hi Phil,

I've been working on this pretty solidly. Pleased to report good progress on the 'macro + batch file' approach. Now have five writing routines working:

Write Comments.TXT for folder
Write Comments-All.TXT for folder+subs
Write separate Comments.TXT for folder+subs
Write Comments.CSV for folder
Write Comments-ALL.CSV for folder+subs


All three use the same technique. I'll show the simplest below, as the Macro Express Pro script is pretty self-explanatory and I imagine not that different to that of other scripting programs. This could help others as well as being useful background for our continuing discussion here.


// This writes a file Comments.TXT about all images in current folder.
// Creates batch file to do this (replacing previous contents) and then runs it.
Text Box Display: Initial Instructions // Just says what macro will do. Redundant after a while.
Text Type (Simulate Keystrokes): <ALT>d // Windows Explorer shortcut for selecting text in Address box.
Delay: 0.2 seconds
Clipboard Copy
Variable Set String %tFolderFullTitle% from the clipboard contents // Defines a text variable tFolderFullTitle (no quotes around it).

// Now the key command, based on ExifTool Forum answers from PH. Unlikely I'll ever be able to construct them myself from first principles!
Variable Set String %tCommand% to "exiftool -T -filename -datetimeoriginal -comment  "%tFolderFullTitle%" > "%tFolderFullTitle%\Comments.txt""

Program Launch: "TEXTPAD.EXE" (Normal)
Parameters: C:\Batch\ExifTool-Batch.bat // Opens a working file in my text editor.
Text Type (Simulate Keystrokes): <CONTROL>a // Select all existing previous content.
Delay: 0.1 seconds
Text Type (Simulate Keystrokes): <DELETE> // Delete all existing previous content.
Delay: 0.1 seconds
Text Type (Simulate Keystrokes): %tCommand%<ENTER> // Type Commmand.
Delay: 0.1 seconds
Text Type (Simulate Keystrokes): <CONTROL>s // Save the batch file.
Delay: 0.1 seconds
Text Type (Simulate Keystrokes): <CONTROL><F4> // Close TextPad temporary file.
Delay: 1 seconds

Program Launch: "ExifTool-Batch.bat" (Normal)
Parameters:  // Run the batch file.
// No EXIT command was used in batch file, but seems unnecessary. The Command Prompt appears while execution is occurring (not sure if I can avoid that?) and then closes automatically.


So I'm abandoning the 'macro + command prompt' approach. Therefore the subject heading is no longer relevant. Probably better as something like 'Using batch files with ExifTool', here or in Newbies?

I now need to develop the macros for 'CSV restoring'. I'll post new threads if necessary.

Thanks again for all your invaluable help so far.

Edited afterthought: I'm guessing that a batch expert could probably do all of that, entirely avoiding the use of macros. But I reckon maintenance would be harder...

--
Terry, East Grinstead, UK



Tarn

Hi Terry,

  I'm not sure what you mean by maintenance in regards to batch files.

Quote from: terrypin on March 26, 2013, 05:23:54 AM
... I'm guessing that a batch expert could probably do all of that, entirely avoiding the use of macros. But I reckon maintenance would be harder...

  I you mean open a batch file; make a change; save it as a copy; over and over again... then yes, keeping track of every version of a given batch file can become a chore (trust me on this one). Other than the initial creating of a batch file, there is no maintenance to speak of. There is, for example, the case where I have a batch file copy files into my "Working" directory; and once done with them I move them to the "Archive" drive. Now I need to remember to go back and delete the source files. NOTE: NEVER "do it later". It'll never get done, and then you have to figure out if you worked on them or not. ;)

  I agree, being able to right click in explorer would be a quick and easy way to work on a directory, or several directories. But I find myself using explorer less and less. In fact I processed and check over 200 directories last night... never opened explorer once. (I'm being pulled into the dark side!)

My 2ยข

terrypin

Hi Tarn,

No, I didn't mean that. Routine like that is common to just about any file system.

I meant I suspect that a batch file that did exactly what my macro did would not be as easy to understand and edit at a later date. At least by the likes of me!

And of course this assumes that it's possible? If so, maybe if you have time you could convert it exclusively into batch form and see what it looks like?

Do you have any suggestion about avoiding the Command Prompt appearing while execution is occurring please?

--
Terry, East Grinstead, UK

Tarn

Hi Terry,

I'll answer the last question first. To the best of my knowledge, there is no way to keep the DOS window from opening when any command is given that operates at the command line level.

As for automating your files, I will give it a try. Keep in mind that I'm no expert at scripting or ExifTool. What I know, I know well. What I don't know, is overwhelming. :)

One thing that might help you understand batch files. A batch file is nothing more than the commands that you would type (manually) at the keyboard; put into a simple text file. Outside of having to double the percent sign "%", anything you would type at the command prompt can go into a batch file.

Give me a few days and I'll see what I can come up with. No promises, but I'll have a go at it.

Tarn

Hi Terry,

    While I didn't do an exhaustive search, I did do enough to begin drawing the conclusion that DOS does not have a practical way of doing what you want.

    Both ExifTool and DOS "almost" do it, but neither one gets the job done the way you want. The problem from my view point (DOS, batch files, etc.) is getting the batch file to recurse into subdirectories the way that ExifTool does. Using the power of ExifTool to do the recursing, and out put that to a txt file results in only one text file. The reason being that the redirect "> out.txt" is done for the command, which is executed in only one directory.

    Keep in mind that this is my first attempt with csv files, so I'm sure that I'm not seeing many of the, what I call, tricks that get the desired output. But at this point I keep thinking that writing a script that would do the recursing; and execute the command in each subdirectory would be the route to take.

    It would be like typing the command at the prompt... changing to the next directory, or subdirectory, and typing the command again... changing to the next directory, or subdirectory, and typing the command again... and so on.

   And I will honest, I have no clue how to do that in a batch file. Nor have I any clue if that can be done from a script.

Phil,
    Is there a way to pass the value of "$Directory" to the DOS equivalent of "%CD%"? Meaning that when ExifTool recurses into, say "Working\990615_Scenery", which would be returned by "-Directory", or "$Directory", that could be assigned to %CD%. Then the statement: "> %%CD%%\out.txt" might (I said might) work.

    At this point, I would suggest that you created the one file, that includes the data from all subdirectories, for ease of reading. And when you need to restore stuff to the original use the command "Copy u:\Archives\990615_Scenery\990615-1955.JPG". In other words, rely on copying, your archives, the file, or files, that you need to restore.

    In short, I don't know how to accomplish what you want to do. And I have serious doubts that I will be able to figure it out. (Unless you figure it out... then it will come to me about 27 seconds after you figure it out).

    But I am really thinking that having the script execute the command as if it were in each directory, and only for that directory, is the answer. Sadly I have no idea how to accomplish that. This does not mean that there is no way to do this, it just means that there is no way that I know how to do it. Remember: The library is full of books about things I know nothing about.

Phil Harvey

Quote from: Tarn on March 27, 2013, 04:24:32 PM
Phil,
    Is there a way to pass the value of "$Directory" to the DOS equivalent of "%CD%"? Meaning that when ExifTool recurses into, say "Working\990615_Scenery", which would be returned by "-Directory", or "$Directory", that could be assigned to %CD%. Then the statement: "> %%CD%%\out.txt" might (I said might) work.

There is no way to change the working directory from within ExifTool.  Also, I don't think your idea will work because the output file is opened only once by the system (just before the exiftool command is run).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

terrypin

Hi Tarn,

I did some more research and after generous help from one of the batch newsgroups I got the following working:

REM This writes Comments.txt in the currently selected folder, containing the 4 fields specified.
REM To run it, drag the Explorer folder onto the batch shortcut
exiftool -T -filename -datetimeoriginal -comment -iptc:caption-abstract -XPComment  "%~1" > "%~1\Comments.txt"


I don't profess to understand it fully. Getting a variable for the current folder was the tricky part. I tried  %cd% and %1 before getting the %~1 suggestion, which proved the winning combination.  :)

It should be easily adaptable to all other more complex ExifTool commands, with care to double up the %s when necessary.

It's satisfied my curiosity, but I'm going to stick with my macro approach. Partly because I had already developed it considerably yesterday. But also because I prefer being able to run the commands from within the folder itself, rather than going up one level to do the drag, and then back again afterwards to open the results.



P.S: Phil, The content of this thread now bears little relation to its subject heading! I'll see what happens if I edit the subject before re-sending this.

--
Terry, East Grinstead, UK

Tarn

Hi Terry,

MY MAN!!!

    I've never been able to get "%~1" to work for me. So I know little about (and understand less).  I tried that a couple of times and it failed every way I tried it. Glad you found something that works.

    Just remember to post a brief "How to" once you get it all figured out. Teach the rest of us how to do that.

Good going.