Computing.Net > Forums > Programming > batch file to copy & increment

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file to copy & increment

Reply to Message Icon

Name: accipiter
Date: March 11, 2009 at 23:55:22 Pacific
OS: Windows XP
CPU/Ram: 2gb
Product: N/a / N/A
Subcategory: Batch
Comment:

I need a batch file to loop through a list of jpgs in a folder, & move them to folders created based on their file names in the following convention:

The folder names will be based on the first 8 characters of the file names, so 09-01556.A2.12.jpg would go in a folder called 09-01556.

I have the following so far which does the job nicely:

for /f %%F in ('dir/b/a-d *.jpg') do call :sub1 %%F
goto :eof

:sub1
set name=%1
md %name:~0,8%
move %* %name:~0,8%


BUT I also need to take account of situations where a jpg file is moved to the destination and it already exists. In this case, I do not want to overwrite, but need to increment the file name whilst preserving the 'previously copied version


SO in the example above, if 09-01556.A2.12.jpg already exists in c:\mydir\09-01556, then the batch command would copy it as 09-01556.A2.12~1.jpg

I am also looking to set this script running with some kind of user interface where it runs every 5sec or so with some kind of indicator to the user that it is running

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: March 14, 2009 at 01:18:19 Pacific
Reply:

Quote:
SO in the example above, if 09-01556.A2.12.jpg already exists in c:\mydir\09-01556, then the batch command would copy it as 09-01556.A2.12~1.jpg

dir %name:~0,8%\%* && (
   move %* %name:~0,8%\%~n*~1%~x* ) || (
   move %* %name:~0,8%)

quote:
I am also looking to set this script running with some kind of user interface where it runs every 5sec or so with some kind of indicator to the user that it is running

title "waiting"
ping -n 5 localhost >nul
tile "running"
%0


0

Response Number 2
Name: Judago
Date: March 14, 2009 at 02:01:05 Pacific
Reply:

What happened to this thred?

Did my script not work??


0

Response Number 3
Name: reno
Date: March 14, 2009 at 02:16:58 Pacific
Reply:

heh, double post maybe?????

i scroll down and looks for old thread that has not been answered. trying to make every thread at least had a response.
and this thread is one of them.


0

Response Number 4
Name: Judago
Date: March 14, 2009 at 02:34:42 Pacific
Reply:

Reno, I think your right, you answered the old one I answered the new one...


0

Response Number 5
Name: accipiter
Date: March 14, 2009 at 06:38:43 Pacific
Reply:

yes, my attempt at multitasking diverged into a different thread
:) Thx


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file to copy & increment

Batch file to copy from network dri www.computing.net/answers/programming/batch-file-to-copy-from-network-dri/14488.html

batch file to copy and move certain www.computing.net/answers/programming/batch-file-to-copy-and-move-certain/11052.html

Batch file to copy to many folders www.computing.net/answers/programming/batch-file-to-copy-to-many-folders/16371.html