copy to desire folders as from text references

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

copy to desire folders as from text references

#1 Post by jamesfui » 05 Apr 2010 09:44

HI dostips Batch Scripter Experts!! 8)
urgently need a script that can read files from the reference text document &
copy the files from a folder through subfolders to the desire folder according to their filetype and will display message when done copying!!

for example, in my c: drive
c:\source\temp\fizzy moon.bmp
c:\source\temp\documents\jan_reports.doc
c:\source\temp\album\malesinger\usher 01.mp3


ref.txt
-----------------content-------------
fizzy moon
jan_reports
usher 01

---------------content end-----------


d:\destination\pictures\fizzy moon.bmp
d:\destination\work\jan_reports.doc
d:\destination\favourite\album\usher 01.mp3


Can bat scripts determine the filetype while getting all the filenames
from the ref.txt(in desktop) & copy them to their desire folders??
if possible, show a message displaying the copy process is done!!

thanks in advance, below is the script i done but it is not working... :(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@echo off
cd /d "%USERPROFILE%\DESKTOP\"

for /f "usebackq delims=" %%a in ('findstr /I /X /g:ref.txt') do xcopy %%~a *.bmp "d:\destination\pictures\"

for /f "usebackq delims=" %%b in ('findstr /I /X /g:ref.txt') do xcopy %%~b *.doc "d:\destination\work\"

for /f "usebackq delims=" %%c in ('findstr /I /X /g:ref.txt') do xcopy %%~c *.mp3 "d:\destination\favourite\album\"

dir /s /b "d:\destination\"*.*>list.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

really need some guides here, why isn't it working?!? :?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: copy to desire folders as from text references

#2 Post by !k » 05 Apr 2010 17:02

Because the wrong syntax. Use the /? for help on command.

Code: Select all

@echo off
setlocal enableextensions

set "source=c:\source\temp"
set "destination=d:\destination"
cd /d %USERPROFILE%\Desktop

for /f "usebackq delims=" %%a in ("ref.txt") do (
if exist "%source%\%%~a.bmp" xcopy "%source%\%%~a.bmp" "%destination%\pictures"
if exist "%source%\%%~a.doc" xcopy "%source%\%%~a.doc" "%destination%\work"
if exist "%source%\%%~a.mp3" xcopy "%source%\%%~a.mp3" "%destination%\favourite\album"
)

dir /s /b "d:\destination">list.txt
start list.txt

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

Re: copy to desire folders as from text references

#3 Post by jamesfui » 06 Apr 2010 02:49

hi !k thanks for your help but
the scripts is not working!!! :(

the scripts looks like coudn't search through the subfolders for the files &
list out nothing copied..

this scripts works on you right?
i wonder why it isn't working in my pc?!?! :?:

any further suggestion? Thanks :)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: copy to desire folders as from text references

#4 Post by !k » 06 Apr 2010 03:02

Oh, sorry, you have the files in subdirectories
c:\source\temp\documents\jan_reports.doc
c:\source\temp\album\malesinger\usher 01.mp3

This is my inattention. Need to modify batch.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: copy to desire folders as from text references

#5 Post by !k » 06 Apr 2010 03:32

Code: Select all

@echo off
setlocal enableextensions

set "source=c:\source\temp"
set "destination=d:\destination"
cd /d %USERPROFILE%\Desktop

for /f "usebackq delims=" %%a in ("ref.txt") do (
pushd "%source%"
for /f "usebackq delims=" %%b in (`dir /s /b /a-d "%%~a.*"`) do (
if "%%~xb"==".bmp" echo d|xcopy "%%~b" "%destination%\pictures"
if "%%~xb"==".doc" echo d|xcopy "%%~b" "%destination%\work"
if "%%~xb"==".mp3" echo d|xcopy "%%~b" "%destination%\favourite\album"
)
)

popd
dir /s /b /a-d "%destination%">list.txt
start list.txt

Post Reply