You are not logged in.
Pages: 1
Hi.
I first wish to appologize for the lengthy and perhaps somewhat convoluted description of what I'm trying to achieve.
I'm using Windows 7.
I've been here before asking how I could load several tabs of photos in a photo viewer application called XnView.
All the responses I got were helpful but ultimately failed, until I realized that I had to reference each photo by their full path
locations, (even though all of the photos are located in the same folder), as shown in the code below.
@echo off
set pathx="C:\Users\User Name\Desktop\xnview"
set pathP="C:\Users\User Name\Desktop\Pics.txt"
set pathA="C:\Users\User Name\Desktop\Photos Folder\"
start "" %pathx% %pathA%01a.jpg %pathA%02a.jpg %pathA%03a.jpg %pathA%04.jpg
I ultimately want to list the photo names/extensions in a seperate text file, "pathP" (that I can manually edit from time-to-time)
and have the batch program retrieve those text file names/extensions and reference them to the actual photo folder(s), and then
have them loaded in the XnView application tabs.
These photo folder paths obviously would be iterated in a loop, and the text file names/extensions appended via the CALL and
tokens= commands - presummably?
The basic coding approach, I assume, is to use the "FOR /F" command and CALL the text file with the list of file names/extensions
and parsed as: 01.jpg 02.jpg 03.jpg ..., and appended to the photo folder paths, and then load those paths in XnView's tabs.
The text file list of images are created by using the "dir /b" command which lists the names/extensions, one per line.
I've tried numerous variations of coding and failed based on what I've gleaned from this site and many others.
I should also mention that I am new to batch scripting, if that isn't already obvious.
My one of many (failed) tenative codeing attempts to use the CALL and TOKENS= commands goes something like this:
FOR /F %%x in %pathA% %%x DO CALL (%pathP% TOKENS=* %%x) in %pathP% DO START "" pathx %%x
Any help or advise would greatly be appreciated!
Thanks!
Offline
Back for an edit to my first post.
Instead of :
"FOR /F %%x in %pathA% %%x DO CALL (%pathP% TOKENS=* %%x) in %pathP% DO START "" pathx %%x"
I'm thinking something more like this is closer to the mark?:
start "" %pathx% (FOR /F TOKENS=* %%y IN %pathP% DO %pathA%%%y)
Which doesn't work either, but hope I'm closing in on it.
In my first aforementioned post bluesxman suggested this code:
for %%x in (%pathA%*.jpg") do start "" %pathx% "%%~x"
...with the "%path_%" variables substituted instead of the written out address.
And, as previously mentioned, I want to be able to append only selected .jpg, .png, etc. files.
bluesxman's code did "work" but it called up several instances of XnView for each .jpg file from the "Photos" folder.
I'm trying to load only one instance of XnView with separate tabs of the files in the "Photo" folder.
So clearly the "START "" %pathx%" portion needs to be outside the FOR loop command.
Anyway, the quest continues... if anyone is... listening?
Offline
You might be able to fudge the list of files to make a single command line, so you're effectively doing
start "" %pathx% file1.jpg file2.jpg fileN.jpg
But it all depends on how your app (XnView?) handles command line params such as this.
So before investing too much time on a solution, I'd test out doing something like this by hand first.
Last edited by bluesxman (03 Apr 2019 13:52)
cmd | *sh | ruby | chef
Offline
Thanks bluesxman for your response. I really do appreciate your suggestion!
If I understand you correctly, the following code, as shown above, does open the photo files in tabs in XnView:
start "" %pathx% %pathA%01a.jpg %pathA%02a.jpg %pathA%03a.jpg %pathA%04.jpg
As you can see, simply appending the file name (as you had earlier suggested) with the path variable does the job.
However, my dilemma now is trying to:
1. retrieve the text file photo names - which I am unable to do despite following the examples shown here on the SS64 site under the "FOR /F" and "TOKENS=" topics;
and 2. appending them, essentially in the same way as shown above, i.e.: %pathA%01.jpg %pathA%02.jpg...etc., except doing so via the "FOR /F" - "TOKENS=" loop commands, thus loading all the text file listings in the XnView app. (which the above code shown does do - "by hand")
...except I need to retrieve various different file extension types from the editable text file, and load various other files from other folders, along with all these loaded tabs as well.
It seems like it would be such a simple straight forward exercise, based on examples shown on this site, and elsewhere, so I'm missing something...besides brains, because I've tried numerous approaches and their permutations to no avail.
Anyway, thanks again for your input bluesxman!
Offline
Re-Edit:
BTW: I forgot to show my latest (what seems to be the most logical approach) coding attempt:
@ECHO OFF
SET pathx="C:\Users\User Name\Desktop\xnview"
SET pathP="C:\Users\User Name\Desktop\Pics.txt"
SET pathA="C:\Users\User Name\Desktop\Photos Folder\"
START "" %pathx% For /F "tokens=*" %%y in (%pathP%) do (%pathA%)%%y [----- or even----- %pathA%%%y]
All that happens is the XnView app comes up "blank".
I've also run the code in the command prompt window, w/o the extra "%" sign for the y variable, of course.
It too does the same as the batch code file, and it does so w/o any objections, error listing, etc.
It seems fine with this coding, except it won't do all of what I thought it should do.
Offline
cmd simply doesn't work in the manner you're trying to make it -- it looks a bit like you're expecting it to behave like an object oriented language. It's nowhere near that clever I'm afraid.
You're going to have to do something like this:
@ECHO OFF
SET pathx="C:\Users\User Name\Desktop\xnview"
SET pathP="C:\Users\User Name\Desktop\Pics.txt"
SET pathA="C:\Users\User Name\Desktop\Photos Folder"
REM we need to be in the photos folder; quit early if we can't get to it for some reason
cd /d "%pathA%" || exit /b 1
REM create the list file (unless it already exists -- assumes you've edited it and don't want to lose changes)
REM you've not made it clear how you want to handle updating this file while keeping your changes, so we never overwrite it
if not exist "%pathP%" (
(for %%i in (*.jpg) do echo:"%%~i") > "%pathP%"
)
REM make sure the variable we are about to fill with files is empty
set "files="
REM load the files from the text file and populate a variable with the values (but only if they actually exist in the current directory)
REM if you have a LOT of files, you might fill the variable (the limit is something like 8000 characters, if memory serves me correctly)
REM but xnview/windows will probably barf before you reach this limit
for /f "usebackq tokens=* delims=" %%f in ("%pathP%") do if exist ".\%%~nxf" call set "files=%files% "%%~nxf""
REM start xnview with a (potentially) long list of files
start "" "%pathx" %files%
Last edited by bluesxman (12 Apr 2019 08:08)
cmd | *sh | ruby | chef
Offline
Thanks again for your response and time bluesxman!
I'm still going over your code. As previously mentioned I'm a novice at batch programming and need time to digest it.
I also have a question about how to make the "FOR /F" and "TOKENS=" commands run properly.
I've used the example given here on the SS64 site under the "FOR /F" command topice:
FOR /F "tokens=1,3 delims=," %%G IN (weather.txt) DO @echo %%G %%H
I've created a "weather.txt" file with data corresponding to the tokens and delims values and copied the file in several different directory locations, just to be sure that it is found by the program, since I had difficulty getting it to even find the file.
I've used single "%" in the parameter variables in the tokens and delim commands when runing in the command prompt window.
Running the program the result gives:
"C:\Users\User Name\Desktop\weather.txt was unexpected at this time", where I explicitely have given the path location in place of the "(weather.txt)"in the above example.
Needless to say I've tried numerous variations with similar rersults.
What the hell am I doing wrong!!!
I believe if I can get this code to run properly it will work in my latest code version.
If nothing else, I want to know how the hell this sh** works!!!!!!!!!!!!
O.K....I better sign off now before I break my keyboard.
Thanks again for your help.
Offline
Zebra if you can post the full code you are trying to run, it will be much easier to see where it is going wrong.
you may need to put double quotes around the full path to weather.txt
Offline
Corrected a bug in my code above (sorry I should have mentioned that I've not run it)
cmd | *sh | ruby | chef
Offline
Hi Simon,
Thanks for your response.
I'm not sure if your asking about the "FOR /F" loop example mentioned above or the code for my original project.
I'll assume you're asking about the FOR /F loop code which I took directly from your "FOR /F" command page examples for the TOKENS= option command.
I lifted that code directly from your example, but substituted the "weather.txt" file name with the path address to a file by the same name.
The path address has no spaces in any part of it so I assume it doesn't require double quotes.
Nevertheless, I did run it with quotes, to the same effect.
Here's one of my code attempts syntax that I ran in the command prompt window:
FOR /F "tokens=1,3 delims=," %G IN C:\Users\J\Desktop\weather.txt DO @echo %G %H
Mind you, I've tried numerous variations besides this attempt with similar failure results.
I also ran a batch file version (using double % signs for the parameter variables, of course) with no effect.
My "weather.txt" file data was delimited by commas with simple numbers and letters, so:
1,2,3,4,5
a,b,c,d,e
v,w,x,y,z
to keep it simple.
The code simply won't pass as advertised, so I'm obviously doing something really stupid and can't see it...or what?.
I hope this is sufficient for what you were asking to look at.
Let me know if you require any other info.
Thanks for your kind assistance!
J.
Offline
You missed out the parenthesis so it needs to be
FOR /F "tokens=1,3 delims=," %G IN (C:\Users\J\Desktop\weather.txt) DO @echo %G %H
Offline
OK!
Great Simon!
Your code worked, although I'm surprised I didn't try this because I tried numerous variations and I would have sworn I tried this code.
Now I'll attempt to integrate this into my original project.
Thanks again Simon, and to bluesxman (whose code I also will apply)
Offline
Pages: 1