Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I need a batch file which should export all the images which are placed in the desktop to a specified location in the batch file . kindly guide me since am new batch file creation .

Thanks in advance .
Posted

First thing to understand is that for your purpose desktop is merely a regular directory with special name, under the user's home directory. For example, my desktop on my XP system is here:

c:\Documents and Settings\SAKryukov\Desktop\


For example, on Windows 7 root directory is Users.

In view of that, let's create a batch file to copy all files from one directory to another, through command line parameters.

@echo off

set source=%1
set dest=%2
set mask=%3 %4 %5 %6 %7 %8 %9

if "%source%"=="" goto:error
if "%dest%"=="" goto:error
if "%mask%"=="" goto:error
if NOT EXIST %source% goto:error
if NOT EXIST %dest% goto:error
if NOT EXIST %mask% goto:error

for %%f in (%source%\%mask%) do copy %%f %dest%
goto:eof

:error
echo Error: Specify all three parameters: source destination mask



Usage:

Assume the above text is save in the file cp.exe (warning, do not it copy.bat!):

First parameter: source directory, must exist
Second parameter: destination directory, must exist
More parameters: file masks delimited by blank space; at least one must exist.

cp c:\sa\source c:\sa\dest *.jpg *.tif *.bmp *.png

Attention! Do not use trailing "\" in directory name.

Now, note that typing all that is no easier than typing complete copy command. So, for one-click usage, create a new batch file with one line similar to the usage line shown above.

I recently found that batch files language in modern versions of Windows is not exactly that boring defunct stuff anymore, it's just a bit better. Even functions with parameters are supported (in rather perverted way).

—SA
 
Share this answer
 
v10
Comments
Vinodh.B 10-Feb-11 5:54am    
am getting error when i click cp.exe
Sergey Alexandrovich Kryukov 10-Feb-11 9:41am    
Yes, of course. Please read usage.
--SA
Vinodh.B 10-Feb-11 9:50am    
Could you lay the procedures to execute the exe . eg do we need to execute promp in cmd or double click .
Sergey Alexandrovich Kryukov 10-Feb-11 9:58am    
OK, here is the fool-proof update.
--SA
Sergey Alexandrovich Kryukov 10-Feb-11 9:59am    
Lay what?
--SA
I have different idea:

I'll give you a batch file that generate complete documentation on writing batch files:

Help generator — batch file.

This is not my work. Sorry, cannot tell the author right now; should be somewhere on my records.

Now, run this batch file, generate documentation and read it.
For more introductory information, Google for batch file programming.
Have fun!

—SA
 
Share this answer
 
Why don't you use Microsoft SyncToy and lit it take care of this for you?
 
Share this answer
 
How about this:

copy %userprofile%\desktop\*.jpg C:\MyImages\
copy %userprofile%\desktop\*.png C:\MyImages\
copy %userprofile%\desktop\*.bmp C:\MyImages\


If your images have other file extensions, you can add lines for them.
If your destination folder is not C:\MyImages, you can write a different path there.
 
Share this answer
 
Comments
Vinodh.B 10-Feb-11 2:22am    
can you provide the complete Code since the above query does not seems to work .
Sergey Alexandrovich Kryukov 10-Feb-11 2:33am    
This is because there is not pre-defined userprofile. Please see my code -- tested.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900