Hi members..Small help needed
Moderator: DosItHelp
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Hi members..Small help needed
I have around 200 images of different dimensions in a directory.
Is it possible in .bat or .vbs to copy images of only 100*50 dimension.
Please help
Is it possible in .bat or .vbs to copy images of only 100*50 dimension.
Please help
Re: Hi members..Small help needed
Install the free and very handy Irfanview to "c:\program files\Irfanview" and try this batch file.
http://www.irfanview.net/
As it stands it will only echo the files to be copied - remove the 'echo' keyword on the third last line to actually perform the copy.
Duplicate the last loop if you also want " 50 x 100 " sized images.
This will leave tmpinfo1/2/3.txt in the folder for you to examine if you need to.
http://www.irfanview.net/
As it stands it will only echo the files to be copied - remove the 'echo' keyword on the third last line to actually perform the copy.
Duplicate the last loop if you also want " 50 x 100 " sized images.
This will leave tmpinfo1/2/3.txt in the folder for you to examine if you need to.
Code: Select all
@echo off
setlocal enabledelayedexpansion
del tmpinfo?.txt
"c:\Program Files\Irfanview\i_view32.exe" *.* /info=tmpinfo.txt
findstr /i /c:"Image dimensions = " /c:"[" tmpinfo.txt >tmpinfo2.txt
for /f "delims=[]" %%a in (tmpinfo2.txt) do (
if defined var (
echo. "!var!"^|"%%a">>tmpinfo3.txt
set "var="
) else (
set "var=%%a"
)
)
for /f "delims=|" %%a in ('find " 100 x 50 "^<tmpinfo3.txt') do (
echo copy %%a "d:\target folder"
)
pause
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Re: Hi members..Small help needed
Hi foxidrive thanks for ur help..
But I guess thats not exactly what I want.
Right now my script is like this
I am just learning.please help me to understand better.
Thanks
But I guess thats not exactly what I want.
Right now my script is like this
Code: Select all
@echo off
cd %1
:copypng
for /r %%i in (*.png) do copy /y "%%i" "D:\target folder"
After running this I get all the png files where as I need only .png files of 100x50 dimensions.
I am just learning.please help me to understand better.
Thanks
Re: Hi members..Small help needed
Did you try the irfanview code with *.png?
Plain cmd doesn't have a method of interrogating the resolution of images. I'm not sure if VB script can do it or not.
Plain cmd doesn't have a method of interrogating the resolution of images. I'm not sure if VB script can do it or not.
Re: Hi members..Small help needed
@foxidrive
Greetings foxidrive,
Using my keyboard I hammered your script in shape for my use. Possible use/edit by others that use Iview in a batch file.
Note: Added 'bells and whistles' no change to the batch engine.
Apologies for stepping on the OP post. I hope the OP gets his/her task resolved.
Best Wishes foxidrive.
Edit: How rude of me. Thank you for the script!
Greetings foxidrive,
Using my keyboard I hammered your script in shape for my use. Possible use/edit by others that use Iview in a batch file.
Note: Added 'bells and whistles' no change to the batch engine.
Code: Select all
@echo off
::Tested .jpg, .png, .bmp. All script lines indented 3 spaces.
setlocal enabledelayedexpansion
echo Files will NOT be copied. Examine tmpinfo4.bat and run that file
echo for desired results.
echo.
If exist tmpinfo?.??t del tmpinfo?.??t
set view=c:\utilities\irfanview\i_view32.exe
echo Enter the file extension ONLY to be copied [jpg png bmp] etc
set/p ext=without the period/full stop:
cls
echo.
echo Enter the Width and Height of the %ext% to be copied.
set /p pic_w=What is the %ext%s Width?:
set /p pic_h=What is the %ext%s Height?:
cls
%view% *.%ext% /info=tmpinfo.txt
findstr /i /c:"Image dimensions = " /c:"[" tmpinfo.txt >tmpinfo2.txt
for /f "delims=[]" %%a in (tmpinfo2.txt) do (
if defined var (
echo. "!var!"^|"%%a">>tmpinfo3.txt
set "var="
) else (
set "var=%%a"
)
)
for /f "delims=|" %%a in ('find " %pic_w% x %pic_h% "^<tmpinfo3.txt') do (
echo copy %%a "c:\bin\test">>tmpinfo4.bat & echo copy %%a "c:\bin\test"
)
:end
echo Press the Space Bar to Close this Window.
pause>nul
del tmpinfo?.txt
Apologies for stepping on the OP post. I hope the OP gets his/her task resolved.
Best Wishes foxidrive.
Edit: How rude of me. Thank you for the script!
Re: Hi members..Small help needed
Thanks OcalaBob, a tip of the Fedora. 

Re: Hi members..Small help needed
Only an VBScript alternative for people who won't install a 3rd party.
getdimensions.vbs
You can run it without an argument for iterating across the current folder or run it with a folder path as argument.
It returns the file path (enclosed in quotes) and the dimension (separated by question marks) if the dimension property isn't empty.
Example:
Regards
aGerman
getdimensions.vbs
Code: Select all
If WScript.Arguments.Count = 0 Then
f = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Else
f = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(WScript.Arguments(0))
End If
Set objFolder = CreateObject("Shell.Application").NameSpace(f)
If objFolder Is Nothing Then WScript.Quit 1
Set colItems = objFolder.Items
For Each objItem In colItems
d = objItem.ExtendedProperty("Dimensions")
If objItem.isFileSystem And Not d = "" Then
WScript.Echo """" & objItem.path & """?" & d
End If
Next
Set objItem = Nothing : Set colItems = Nothing : Set objFolder = Nothing
You can run it without an argument for iterating across the current folder or run it with a folder path as argument.
It returns the file path (enclosed in quotes) and the dimension (separated by question marks) if the dimension property isn't empty.
Example:
Code: Select all
@echo off
for /f "tokens=1,2 delims=?" %%i in ('cscript //nologo getdimensions.vbs') do (
echo %%i
echo %%j
if /i "%%j"=="100 x 50" echo COPY ME
echo --------------------------------
)
pause
Regards
aGerman
Re: Hi members..Small help needed
aGerman wrote:Only an VBScript alternative for people who won't install a 3rd party.
getdimensions.vbs
That's a neat bit of code to stash away. Ta.
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Re: Hi members..Small help needed
aGerman wrote:Only an VBScript alternative for people who won't install a 3rd party.
getdimensions.vbsCode: Select all
If WScript.Arguments.Count = 0 Then
f = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Else
f = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(WScript.Arguments(0))
End If
Set objFolder = CreateObject("Shell.Application").NameSpace(f)
If objFolder Is Nothing Then WScript.Quit 1
Set colItems = objFolder.Items
For Each objItem In colItems
d = objItem.ExtendedProperty("Dimensions")
If objItem.isFileSystem And Not d = "" Then
WScript.Echo """" & objItem.path & """?" & d
End If
Next
Set objItem = Nothing : Set colItems = Nothing : Set objFolder = Nothing
You can run it without an argument for iterating across the current folder or run it with a folder path as argument.
It returns the file path (enclosed in quotes) and the dimension (separated by question marks) if the dimension property isn't empty.
Example:Code: Select all
@echo off
for /f "tokens=1,2 delims=?" %%i in ('cscript //nologo getdimensions.vbs') do (
echo %%i
echo %%j
if /i "%%j"=="100 x 50" echo COPY ME
echo --------------------------------
)
pause
Regards
aGerman
Hi aGerman,
First off all I really appreciate all the members here for giving their valuable time and effort.
Thank you for helping me this far.
I still have some problems.I am complete new to programming so please have patience if I ask some stupid questions.
Problem 1.Instead of "echo COPY ME" can I have a code that copies those files on its own,creates a folder and pastes it.
Problem 2.I have noticed it only works with a single folder and not if it has multiple subfolders.
Please guide me.
Re: Hi members..Small help needed
It's all possible but would you please explain before ...
What folder should it create, what's its name and where should it be placed? One new folder for each copied file?
Regards
aGerman
amitananddey wrote:can I have a code that copies those files on its own,creates a folder and pastes it.
What folder should it create, what's its name and where should it be placed? One new folder for each copied file?
Regards
aGerman
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Re: Hi members..Small help needed
aGerman wrote:It's all possible but would you please explain before ...amitananddey wrote:can I have a code that copies those files on its own,creates a folder and pastes it.
What folder should it create, what's its name and where should it be placed? One new folder for each copied file?
Regards
aGerman
Sorry for my poor explanation.
I have a folder structure like this
E:\COLORS
├───blue
│ └───1
│ ├───a.png
│ ├───b
│ └───c.png
├───green
│ └───1
│ ├───a
│ ├───b
│ └───c.png
├───oragne
│ └───1
│ ├───a
│ ├───b.png
│ └───c
└───red
└───1
├───a.png
├───b
└───c
The png's present in my folder are of different dimension.When I drag and drop "COLORS" folder to the batch script it should create a unique folder of any name inside the same path "E:\COLORS" and pastes all .png of 100*50 dimension inside the unique folder.
Hope its clear.
Re: Hi members..Small help needed
Do you want one unique folder for every 100x50 image (say a folder called 100x50)
or do you want a unique folder inside of every other folder in the tree, and then place the 100x50 images in that folder.
So do you want this for every image of 100 x 50
e:\colors\100x50
or this style of structure?
e:\colors\blue\100x50
e:\colors\blue\1\100x50
e:\colors\blue\b\100x50
e:\colors\green\100x50
e:\colors\green\1\100x50
or do you want a unique folder inside of every other folder in the tree, and then place the 100x50 images in that folder.
So do you want this for every image of 100 x 50
e:\colors\100x50
or this style of structure?
e:\colors\blue\100x50
e:\colors\blue\1\100x50
e:\colors\blue\b\100x50
e:\colors\green\100x50
e:\colors\green\1\100x50
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Re: Hi members..Small help needed
foxidrive wrote:Do you want one unique folder for every 100x50 image (say a folder called 100x50)
or do you want a unique folder inside of every other folder in the tree, and then place the 100x50 images in that folder.
So do you want this for every image of 100 x 50
e:\colors\100x50
or this style of structure?
e:\colors\blue\100x50
e:\colors\blue\1\100x50
e:\colors\blue\b\100x50
e:\colors\green\100x50
e:\colors\green\1\100x50
Hi foxidrive,
I want one single unique folder inside e:\colors where all my 100*50 images will be placed.
Like this e:\colors\100x50
e:\colors\100x50
Re: Hi members..Small help needed
Make sure that you place this batch file and also "get image dimensions.vbs" as listed below in "e:\color" and then run the batch file.
What hasn't been discussed is the possibility of filename clashes where a file in two different folders may have the same name.
This code renames the files as they are copied to "foldername - filename.ext" to help a little in this regard.
If you anticipate numerous filename clashes then it will need the addition of a random number to the filename.
"get image dimensions.vbs" (same code as as getdimensions.vbs)
What hasn't been discussed is the possibility of filename clashes where a file in two different folders may have the same name.
This code renames the files as they are copied to "foldername - filename.ext" to help a little in this regard.
If you anticipate numerous filename clashes then it will need the addition of a random number to the filename.
Code: Select all
@echo off
:: copies all images of 100 x 50 dimension to .\100x50 folder
set "folder=%cd%"
set "target=%folder%\100x50"
if not exist "%folder%\get image dimensions.vbs" (
echo "%folder%\get image dimensions.vbs" does not exist
pause
goto :EOF
)
md "%target%" 2>nul
for /f "delims=" %%a in ('dir "%folder%" /ad /b /s ^|find /v "%target%"') do (
for /f "tokens=1,2 delims=?" %%b in ('cscript //nologo "%folder%\get image dimensions.vbs" "%%a"') do (
echo.%%c - %%b
if /i "%%c"=="100 x 50" (
echo copying "%%~b"
copy /b "%%~b" "%target%\%%~nxa-%%~nxb" >nul
)
)
)
pause
"get image dimensions.vbs" (same code as as getdimensions.vbs)
Code: Select all
If WScript.Arguments.Count = 0 Then
f = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Else
f = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(WScript.Arguments(0))
End If
Set objFolder = CreateObject("Shell.Application").NameSpace(f)
If objFolder Is Nothing Then WScript.Quit 1
Set colItems = objFolder.Items
For Each objItem In colItems
d = objItem.ExtendedProperty("Dimensions")
If objItem.isFileSystem And Not d = "" Then
WScript.Echo """" & objItem.path & """?" & d
End If
Next
Set objItem = Nothing : Set colItems = Nothing : Set objFolder = Nothing
-
- Posts: 14
- Joined: 16 Jan 2012 04:56
Re: Hi members..Small help needed
foxidrive wrote:Make sure that you place this batch file and also "get image dimensions.vbs" as listed below in "e:\color" and then run the batch file.
What hasn't been discussed is the possibility of filename clashes where a file in two different folders may have the same name.
This code renames the files as they are copied to "foldername - filename.ext" to help a little in this regard.
If you anticipate numerous filename clashes then it will need the addition of a random number to the filename.Code: Select all
@echo off
:: copies all images of 100 x 50 dimension to .\100x50 folder
set "folder=%cd%"
set "target=%folder%\100x50"
if not exist "%folder%\get image dimensions.vbs" (
echo "%folder%\get image dimensions.vbs" does not exist
pause
goto :EOF
)
md "%target%" 2>nul
for /f "delims=" %%a in ('dir "%folder%" /ad /b /s ^|find /v "%target%"') do (
for /f "tokens=1,2 delims=?" %%b in ('cscript //nologo "%folder%\get image dimensions.vbs" "%%a"') do (
echo.%%c - %%b
if /i "%%c"=="100 x 50" (
echo copying "%%~b"
copy /b "%%~b" "%target%\%%~nxa-%%~nxb" >nul
)
)
)
pause
"get image dimensions.vbs" (same code as as getdimensions.vbs)Code: Select all
If WScript.Arguments.Count = 0 Then
f = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Else
f = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(WScript.Arguments(0))
End If
Set objFolder = CreateObject("Shell.Application").NameSpace(f)
If objFolder Is Nothing Then WScript.Quit 1
Set colItems = objFolder.Items
For Each objItem In colItems
d = objItem.ExtendedProperty("Dimensions")
If objItem.isFileSystem And Not d = "" Then
WScript.Echo """" & objItem.path & """?" & d
End If
Next
Set objItem = Nothing : Set colItems = Nothing : Set objFolder = Nothing
Thanks foxidrive,
Works like charm......
You guys are masters...