I want to create a batch script which can search for .jpg an
Moderator: DosItHelp
I want to create a batch script which can search for .jpg an
I want to create a batch script which can search for .jpg and .jpeg
I am new to this script language, so don't no how to search, so I am posting this thread here.
Please can anyone tell me the batch script which can search all drives and folders and subfolders in a computer for .jpg and .jpeg, once found they must get copied.
Please help me with this, please give me the script code for this.
I am new to this script language, so don't no how to search, so I am posting this thread here.
Please can anyone tell me the batch script which can search all drives and folders and subfolders in a computer for .jpg and .jpeg, once found they must get copied.
Please help me with this, please give me the script code for this.
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
UNTESTED
Code: Select all
@echo off
set "rootdir=c:\root folder to search"
set "destdir=c:\where you want to copy"
for /f "delims=" %%a in ('dir /b /s /a-d "%rootdir%\*.jpg" "%rootdir%\*.jpeg") do copy "%%~a" "%destdir%"
avery_larry wrote:UNTESTEDCode: Select all
@echo off
set "rootdir=c:\root folder to search"
set "destdir=c:\where you want to copy"
for /f "delims=" %%a in ('dir /b /s /a-d "%rootdir%\*.jpg" "%rootdir%\*.jpeg") do copy "%%~a" "%destdir%"
Din't worked
I have a script, the thing is it will enter in physical drive and look if there's any .jpg is there or not, but doesn't enter into the folders inside the physical drive, can anyone modify this script so that it should enter in physical drive and as well as search in folders and subfolders for the .jpeg and copy the item.
The script is here.
@echo off
for /F %%a in ('mountvol ^| find ":"') do (
dir %%a 1>nul 2>nul
if not ErrorLevel 1 (
copy %%a*.jpg
copy %%a*.jpeg
)
)
The code by avery_larry works;
it just has a small typo error... he forgot the single quote ending at the bracket:
('dir /b . . . . . jpeg"')
Place this batch file in a new folder anywhere you like (and click on it). . .
--------------------code start------------------------------
@echo off
set "rootdir=%systemroot%"
set "destdir=%cd%"
for /f "delims=" %%a in ('dir /b /s /a-d "%rootdir%\*.jpg" "%rootdir%\*.jpeg"') do copy "%%~a" "%destdir%"
pause
---------------------code end-----------------------------
WOW ... I didn't know I had so many 'images' there !
By the way avery_larry. . .
what is this switch for [/a-d], in the DIR command?
it just has a small typo error... he forgot the single quote ending at the bracket:
('dir /b . . . . . jpeg"')
Place this batch file in a new folder anywhere you like (and click on it). . .
--------------------code start------------------------------
@echo off
set "rootdir=%systemroot%"
set "destdir=%cd%"
for /f "delims=" %%a in ('dir /b /s /a-d "%rootdir%\*.jpg" "%rootdir%\*.jpeg"') do copy "%%~a" "%destdir%"
pause
---------------------code end-----------------------------
WOW ... I didn't know I had so many 'images' there !
By the way avery_larry. . .
what is this switch for [/a-d], in the DIR command?
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
the /a-d switch keeps it from matching any directories. Unlikely, but not impossible, to have a directory ending with .jpg or .jpeg. Mostly I put it there because that's what I commonly do when using that type of dir statement in a for statement that should be only for filenames, not directory names.
Thanks for the answer avery_larry.
When I typed dir /? at command line I got:
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
How am I supposed to figure out that switch from that output !?
...and to think /? is meant to indicate . . .help !!!
I don't think I'm totally dumb, but all those closed brackets have me going cross-eyed.
When I typed dir /? at command line I got:
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
How am I supposed to figure out that switch from that output !?
...and to think /? is meant to indicate . . .help !!!
I don't think I'm totally dumb, but all those closed brackets have me going cross-eyed.
A small Clarification...
Hi avery..
What is the use of ~ near teh variable %%a?
Even if we remove it, it is working fine...
I just want to know if there is any specific reason for that....
What is the use of ~ near teh variable %%a?
Even if we remove it, it is working fine...
I just want to know if there is any specific reason for that....
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
%%~a will remove any surrounding double quotes. But you must have double quotes for any filename or path that contains a space. Therefore, mostly because it's goo form, I tend to double quote any file or path that could possibly ever have a space, and I also tend to use the ~ method to make sure I never have double double quotes.
"%%~a"
explicitly removes any surrounding double quotes and then double quotes the resulting variable. In this code, I'm pretty sure that the dir command will NOT return anything in double quotes, so it's not needed -- I just do it out of habit. Nothing worse than trying to troubleshoot a double quote problem someplace in your code.
"%%~a"
explicitly removes any surrounding double quotes and then double quotes the resulting variable. In this code, I'm pretty sure that the dir command will NOT return anything in double quotes, so it's not needed -- I just do it out of habit. Nothing worse than trying to troubleshoot a double quote problem someplace in your code.