I'm not sure whether you will be able to get at file properties like that in a batch script. I would recommend using something like Python. Here is a link to another thread which suggests using the PIL.imaging library for this.
If you are interested in perusing this route but do not know any Python let me know and I can put a quick script together for this.
Instructions to install Python
As discussed you will need to install Python for this to run. I have also found out that PIL is a third party library, so you will also need to download and install this (make sure you pick the same version as your python installation e.g. if you have installed Python 2.7 on 64 bit, you would need "Pillow-2.1.0.win-amd64-py2.7.exe" from here).
Once you have done the install you can check that this is working by opening the command prompt (cmd) and entering c:\python27\python.exe
(if you add c:\python27 top your PATH environment variable you will just need to type "Python"). This will open the python command prompt. Type print "test"
and you should see thr output printed then exit()
.
Once Python is installed you can create a script. Here is some code that will do what you have requested (list all files of a given extension that are found from a base path with 1 1 1 width height to a file).
Open a text editor e.g. notepad paste in the code below and save as "image_attr.py" or whatever name you decide to use:
from PIL import Image
import os, sys
def main():
# if a cmd line arg has been passed in use as base path...
if len(sys.argv) > 1:
base_path = sys.argv[1]
# else use current working dir...
else:
base_path = os.getcwd()
# image file extensions to be included, add or remove as required...
ext_list = ['.bmp', '.jpg']
# open output file...
outfile = os.path.join(base_path,'infofile.txt')
file_obj = open(outfile, 'wb')
# walk directory structure...
for root, dirs, files in os.walk(base_path):
for f in files:
# check of file extension is in list specified above...
if os.path.splitext(f)[1].lower() in ext_list:
f_path = os.path.join(root, f)
width, height = Image.open(f_path).size
output = f_path + ' 1 1 1 ' + str(width) + ' ' + str(height) +'\r\n'
file_obj.write(output)
file_obj.close()
if __name__ == '__main__':
main()
Save this and remember the path to the file, I will use c:\python27\image_attr.py
for this example. You can then call this from cmd or from a batch script passing in an arguement for the base path e.g.:
python c:\python27\image_attr.py E:\Users\Prosserc\Pictures
Please note that any arguements with spaces in them should be enclosed with double quotes.
Please let me know if you have any questions.
EDIT
For Python 3 the amendments should be minimal in theory. In this case I am writing the output the the screen rather than a file, but redirecting to a file from cmd:
from PIL import Image
import os, sys
def main():
# if a cmd line arg has been passed in use as base path...
if len(sys.argv) > 1:
base_path = sys.argv[1]
# else use current working dir...
else:
base_path = os.getcwd()
# image file extensions to be included, add or remove as required...
ext_list = ['.bmp', '.jpg']
# walk directory structure
for root, dirs, files in os.walk(base_path):
for f in files:
# check of file extension is in list specified above...
if os.path.splitext(f)[1].lower() in ext_list:
f_path = os.path.join(root, f)
width, height = Image.open(f_path).size
output = f_path + ' 1 1 1 ' + str(width) + ' ' + str(height) +'\r\n'
print(output)
if __name__ == '__main__':
main()
Call with:
python c:\python27\image_attr.py E:\Users\Prosserc\Pictures > infofile.txt