| 1. |
Solve : DOS Command to capture image names & output to Excel ?? |
|
Answer» Hi - i have 1000's of product images (mostly JPG / PNG) STORED in a folder. HiNice little .bat file Hackoo. I'd recommend changing the line echo %%i;!list[%%i]!;!listpath[%%i]!>> "%LogFile%" to use commas instead of semi-colons, that way Excel will put the count, file name and location in separate columns. As for Salmon's comment regarding .bmp files, any other type of image files can be added to the line: Set "EXT=jpg png gif bmp tif" or in my original command: for %x in (*.jpg *.gif *.png *.bmp *.tif) do echo %x , >> out.csvNew script to search for [jpg png gif bmp tif] with ShowBalloonTip function in powershell for fancy ImagesFinder.bat Code: [Select]echo off Title Search for images files mode con cols=75 lines=5 & Color 0A REM We set the variable Folder Set "Folder=%USERPROFILE%\Pictures" Rem We set the variable EXT for the extensions images to be searched by the script Set "EXT=jpg png gif bmp tif" REM We initialize the variable Count from zero for counting images files SET "Count=0" Rem Set the variable LogFile to save the information after the scanning Set "LogFile=%~n0.csv" If exist "%LogFile%" Del "%LogFile%" Set "Msg=Please wait a while scanning for" Setlocal Enabledelayedexpansion For %%a in (%EXT%) Do ( Call :Scanning %%a Call :ShowBalloonTip 'Information' 100 '"%~n0 to find images"' '"%Msg% """*.%%a""" images ..."' 'Info' 10 FOR /f "delims=" %%f IN ('dir /a-d /b /s "%Folder%\*.%%a"') DO ( Rem We increment the variable Count SET /a "Count+=1" rem populate the array variable list with the name of images set "list[!Count!]=%%~nxf" rem populate the array variable listpath with the whole path of images set "listpath[!Count!]=%%~dpFf" ) ) Cls echo( echo Saving information into the file "%LogFile%" echo The Total of [%EXT%] images files(s) found is !Count! rem Display array elements for /L %%i in (1,1,%Count%) do ( rem save information into the LogFile.csv echo %%i,!list[%%i]!,!listpath[%%i]!>> "%LogFile%" ) Start "" "%LogFile%" & exit ::**************************************************************************** :Scanning %1 Cls echo( & echo( echo %Msg% "*.%1" images ... exit /b ::**************************************************************************** :ShowBalloonTip $notifyicon $time $title $text $icon $Timeout PowerShell ^ [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^ [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^ $notify = new-object system.windows.forms.notifyicon; ^ $notify.icon = [System.Drawing.SystemIcons]::%1; ^ $notify.visible = $true; ^ $notify.showballoontip(%2,%3,%4,%5); ^ Start-Sleep -s %6; ^ $notify.Dispose() %End PowerShell% exit /B ::*****************************************************************************Maybe I can contribute something POSITIVE.............. If you have multiple folders in different locations and don't want the bother of putting the script in the "current folder" you're welcome to drop this code into your script. This will let you put your script wherever you want - then - at run-time - you can browse your computer and pick the target folder you want to work with. Obviously, you have to tweak the original script to include this code - and use the variable that returns the folder you picked. And don't forget... make SURE the "EXITs" in this script are removed or modified so when this code ends it doesn't terminate the script it was inserted into. Cheers !! Code: [Select]echo off setlocal enabledelayedexpansion :: set SName=%~dpn0 :: call :SavBrowse :: cls & color 2E :: :: ===================================================================== :: call the folder-finder :: ===================================================================== :: set _Repo= For /f "delims=" %%A in ( 'cscript //nologo "%temp%\900_VBrowse.vbs" "C:\"' ) do set _Repo=%%A :: echo. & echo. echo Selected Folder: %_Repo% echo. & echo. echo. & echo. pause :: :: :: ===================================================================== :: End-of-Script :: ===================================================================== :: cls & color 5E echo. & echo. & echo. & echo. echo. & echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * echo. & echo * %~nx0 echo. & echo * Blah, Blah, Blah........ echo. & echo * echo. & echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * echo. & echo. set /p entered=....Hit any key to continue :: EXIT :: :: :: :: :: :: -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- :: Subroutines :: -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- :: :SavBrowse :: set _aa=Function BrowseForFile() echo %_aa% > %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=xparm = "" echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=xparm = WScript.Arguments.Item(0) echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=Dim shell : Set shell = CreateObject("Shell.Application") echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=Dim file : Set file = shell.BrowseForFolder(0, "Choose a folder:", ^^^&H4000, xparm) echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=BrowseForFile = file.self.Path echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=End Function echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=WScript.echo(BrowseForFile) echo %_aa% >> %temp%\900_VBrowse.vbs goto :EOF As someone who has tinkered with batch/vbs hybrid scripts, I have to ask: why all those set _aa and echo %_aa% commands? Why not just echo the lines directly into the vbscript? It makes the batch harder to read and doubles the number of lines in that section. Also, double-colons (which are really broken labels) as comments are severely deprecated in NT family batch scripting; they may look cool but they can break scripts, e.g. in parenthesis blocks. Not wishing to pour cold water on what is a very neat idea. If you want to use the function Browse4Folder, you can do something like this ImagesFinder.bat Code: [Select]echo off Title Search for images files mode con cols=75 lines=5 & Color 0A REM We set the variable Folder Call :Browse4Folder "Choose source folder to scan for images files" "c:\scripts Set "Folder=%Location%" Rem if the variable %Folder% have a trailing back slash, we remove it ! IF %Folder:~-1%==\ SET Folder=%Folder:~0,-1% If "%errorlevel%" EQU "0" ( echo( & echo( echo You choose this folder "%Folder%" Timeout /T 2 /nobreak>nul ) else ( echo( & echo( echo "%Folder%" Timeout /T 2 /nobreak>nul & Exit ) Rem We set the variable EXT for the extensions images to be searched by the script Set "EXT=jpg png gif bmp tif" REM We initialize the variable Count from zero for counting images files SET "Count=0" Rem Set the variable LogFile to save the information after the scanning For %%f in (%Folder%) do set "LogFile=%~n0_%%~nf.csv" If exist "%LogFile%" Del "%LogFile%" Set "Msg=Please wait a while scanning for" Setlocal Enabledelayedexpansion For %%a in (%EXT%) Do ( Call :Scanning %%a Call :ShowBalloonTip 'Information' 100 '"%~n0 to find images"' '"%Msg% """*.%%a""" images ..."' 'Info' 10 FOR /f "delims=" %%f IN ('dir /a-d /b /s "%Folder%\*.%%a"') DO ( Rem We increment the variable Count SET /a "Count+=1" rem populate the array variable list with the name of images set "list[!Count!]=%%~nxf" rem populate the array variable listpath with the whole path of images set "listpath[!Count!]=%%~dpFf" ) ) Cls echo( echo Saving information into the file "%LogFile%" echo The Total of [%EXT%] images files(s) found is !Count! rem Display array elements for /L %%i in (1,1,%Count%) do ( rem save information into the LogFile.csv echo %%i,!list[%%i]!,!listpath[%%i]!>> "%LogFile%" ) If exist "%LogFile%" ( Start "" "%LogFile%" & exit ) else ( exit ) ::**************************************************************************** :Scanning %1 Cls echo( & echo( echo %Msg% "*.%1" images ... exit /b ::**************************************************************************** :ShowBalloonTip $notifyicon $time $title $text $icon $Timeout PowerShell ^ [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^ [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^ $notify = new-object system.windows.forms.notifyicon; ^ $notify.icon = [System.Drawing.SystemIcons]::%1; ^ $notify.visible = $true; ^ $notify.showballoontip(%2,%3,%4,%5); ^ Start-Sleep -s %6; ^ $notify.Dispose() %End PowerShell% exit /B ::***************************************************************************** :Browse4Folder set Location= set vbs="%temp%\_.vbs" set cmd="%temp%\_.cmd" for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= ( echo set shell=WScript.CreateObject("Shell.Application"^) echo set f=shell.BrowseForFolder(0,"%~1",0,"%~2"^) echo if typename(f^)="Nothing" Then echo wscript.echo "set Location=Dialog Cancelled" echo WScript.Quit(1^) echo end if echo set fs=f.Items(^):set fi=fs.Item(^) echo p=fi.Path:wscript.echo "set Location=" ^& p )>%vbs% cscript //nologo %vbs% > %cmd% for /f "delims=" %%a in (%cmd%) do %%a for %%f in (%vbs% %cmd%) do if exist %%f del /f /q %%f for %%g in ("vbs cmd") do if defined %%g set %%g= goto :eof ::******************************************************************************I am not a "scriptor" - I just solve problems as I encounter them. Everyone has his/her own style so if it works for me - but you don't like what I do - or the way I do it - I still go to sleep at night knowing that it works for me. I'm not trying to sell you anything - I'm just offering code that might be helpful to somebody. I'm very sorry if that offends you to the point you must criticize my efforts. If you must pick-pick-pick I hope you feel better now. I do appreciate the help some have given me in other threads. BlueThere are two ways to accept criticism, you can take it personally, or you can use it to improve. |
|