patch to copy or move my files based on the f

Eidos Lego star wars (xbox)
October 1, 2009 at 07:13:40
Specs: Windows Vista
Please anyone can help me, i just a new learner in the world of batch files,
my q is:
i want a patch to copy or move my files based on the file extension to diff folders
for ex:
*.bat files to be copied to ---> Bat Folder
*.txt files to be copied to ---> Txt Folder
and so on
thanks in advance

See More: patch to copy or move my files based on the f

Report •


#1
October 1, 2009 at 09:36:39
copy [source path]\*.bat [distination path]\foldername

You can google this stuff or go to a cmd prompt and type copy /? for all the syntax.


Report •

#2
October 1, 2009 at 17:05:30
Thanks wanderer for your fast reply.
actually i know a little bit about batch code and i already know that i can make it with copy or xcopy, but may be my question was not right explained from the beginning.
here is what i made but it gave me some error everytime
as file not found or file exist, after finishing copying.

FOR %%J in (TXT_Files BAT_Files CMD_Files ZIP_Files) DO (MD C:\TESTCOPY\%%J)

FOR /R "C:\TESTCOPY" %%F IN (*.TXT *.BAT *.CMD *.ZIP) DO ( MOVE C:\TESTCOPY\*.TXT C:\TESTCOPY\TXT_Files\ && MOVE C:\TESTCOPY\*.BAT C:\TESTCOPY\BAT_Files\ && MOVE C:\TESTCOPY\*.CMD C:\TESTCOPY\CMD_Files\ && MOVE C:\TESTCOPY\*.ZIP C:\TESTCOPY\ZIP_Files\)

::ANOTHER WAY
FOR %%J in (TXT_Files BAT_Files CMD_Files ZIP_Files) DO (MD C:\TESTCOPY\%%J)

MOVE C:\TESTCOPY\*.TXT C:\TESTCOPY\TXT_Files\
MOVE C:\TESTCOPY\*.BAT C:\TESTCOPY\BAT_Files\
MOVE C:\TESTCOPY\*.CMD C:\TESTCOPY\CMD_Files\
MOVE C:\TESTCOPY\*.ZIP C:\TESTCOPY\ZIP_Files\

:: ANOTHER WAY
FOR %%J in (TXT BAT CMD ZIP) DO (MD C:\TESTCOPY\%%J)

FOR %%F IN (TXT BAT CMD ZIP) DO ( MOVE C:\TESTCOPY\*.%%F C:\testcopy\%%F\ && MOVE C:\TESTCOPY\*.%%f C:\testcopy\%%F\ && MOVE C:\TESTCOPY\*.%%F C:\testcopy\%%F\ && MOVE C:\TESTCOPY\*.%%F c:\testcopy\%%F\)

am i going on the right way or i don't understand for is working???

thank you very much again for your reply

forgive me as i'm studying by my own, no one is helping me to do it.


Report •

#3
October 1, 2009 at 17:13:34
here is another code i would like you to tell me is it right or also i used FOR in wrong or long way with keeping in mind that it's working as well as i want, but just i thought may be there is short way to do it

here the code:


@ECHO OFF
TITLE USB Searcher . . .
CLS

:START1

ECHO/
ECHO/ (S) Start Search For HaMaDa USB.
ECHO/ (Q) Quit
ECHO/
CHOICE /C:QS /N /M " :: Press (S) to Start Search or (Q) to exit:
IF ERRORLEVEL 2 GOTO START
GOTO EOF

:START
CLS

ECHO/
:: SET ALL VARIABLE TO NUL
SET USB1=
SET USB2=
SET USB3=
SET USB4=
SET USB5=
SET USB6=
SET USB7=
SET USB8=
SET USB9=
SET USB10=

ECHO/
ECHO/ Searching for HaMaDa USB Drives . . .
ECHO/

:: FOR EACH LETTER FROM THIS LIST MAKE THE ACTION OF DIR %%LETTER AND IF EXIST %%LETTER\xam\ --- SET A VARIABLE FOR USB FROM 1 TO 10
:: FOR EXAMPLE:
:: %USB1% WILL BE [F:\]
:: %USB2% WILL BE [G:\] ----- AND SO ON.

:: FOR EACH LETTER FROM THIS LIST MAKE THE ACTION OF DIR %%LETTER AND IF EXIST %%LETTER\xam\
:: AND IF THE LETTER NOT EQUAL TO THE PREVIOUS ONE --- SET ANOTHER USB FROM 2 TO 10 --------- AND SO ON TILL THE END.

:: IF THE VARIABLE %%LETTER = %% LETTER (MEANS THAT THE LOOP DIDN'T RETURN ANY POSSITIVE RESULT TO FIND THE FOLDER
:: SO GOTO WHATEVER FINISH-END-DONE

:USB1
for %%A in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%A:\ 2>nul 1>&2&&if exist "%%A:\xam\" set "USB1=%%A:\"&&GOTO USB2S
)
IF %%A==%%A SET USB1=
GOTO ERROR

:USB2S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB1%]
for %%B in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%B:\ 2>nul 1>&2&&if exist "%%B:\xam\" IF %USB1% NEQ %%B:\ set "USB2=%%B:\"&&GOTO USB3S
)
IF %%B==%%B SET USB2=
GOTO DONE

:USB3S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB2%]
for %%C in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%C:\ 2>nul 1>&2&&if exist "%%C:\xam\" IF %USB1% NEQ %%C:\ IF %USB2% NEQ %%C:\ set "USB3=%%C:\"&&GOTO USB4S
)
IF %%C==%%C SET USB3=
GOTO DONE

:USB4S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB3%]
for %%D in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%D:\ 2>nul 1>&2&&if exist "%%D:\xam\" IF %USB1% NEQ %%D:\ IF %USB2% NEQ %%D:\ IF %USB3% NEQ %%D:\ set "USB4=%%D:\"&&GOTO USB5S
)
IF %%D==%%D SET USB4=
GOTO DONE

:USB5S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB4%]
for %%E in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%E:\ 2>nul 1>&2&&if exist "%%E:\xam\" IF %USB1% NEQ %%E:\ IF %USB2% NEQ %%E:\ IF %USB3% NEQ %%E:\ IF %USB4% NEQ %%E:\ set "USB5=%%E:\"&&GOTO USB6S
)
IF %%E==%%E SET USB5=
GOTO DONE

:USB6S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB5%]
for %%F in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%F:\ 2>nul 1>&2&&if exist "%%F:\xam\" IF %USB1% NEQ %%F:\ IF %USB2% NEQ %%F:\ IF %USB3% NEQ %%F:\ IF %USB4% NEQ %%F:\ IF %USB5% NEQ %%F:\ set "USB6=%%F:\"&&GOTO USB7S
)
IF %%F==%%F SET USB6=
GOTO DONE

:USB7S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB6%]
for %%G in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%G:\ 2>nul 1>&2&&if exist "%%G:\xam\" IF %USB1% NEQ %%G:\ IF %USB2% NEQ %%G:\ IF %USB3% NEQ %%G:\ IF %USB4% NEQ %%G:\ IF %USB5% NEQ %%G:\ IF %USB6% NEQ %%G:\ set "USB7=%%G:\"&&GOTO USB8S
)
IF %%G==%%G SET USB7=
GOTO DONE

:USB8S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB7%]
for %%H in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%H:\ 2>nul 1>&2&&if exist "%%H:\xam\" IF %USB1% NEQ %%H:\ IF %USB2% NEQ %%H:\ IF %USB3% NEQ %%H:\ IF %USB4% NEQ %%H:\ IF %USB5% NEQ %%H:\ IF %USB6% NEQ %%H:\ IF %USB7% NEQ %%H:\ set "USB8=%%H:\"&&GOTO USB9S
)
IF %%H==%%H SET USB8=
GOTO DONE

:USB9S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB8%]
for %%I in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%I:\ 2>nul 1>&2&&if exist "%%I\xam\" IF %USB1% NEQ %%I:\ IF %USB2% NEQ %%I:\ IF %USB3% NEQ %%I:\ IF %USB4% NEQ %%I:\ IF %USB5% NEQ %%I:\ IF %USB6% NEQ %%I:\ IF %USB7% NEQ %%I:\ IF %USB8% NEQ %%I:\ set "USB9=%%I:\"&&GOTO USB10S
)
IF %%I==%%I SET USB9=
GOTO DONE

:USB10S
ECHO/ Found HaMaDa USB Drive . . . . . [%USB9%]
for %%J in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
dir %%J:\ 2>nul 1>&2&&if exist "%%J:\xam\" IF %USB1% NEQ %%J:\ IF %USB2% NEQ %%J:\ IF %USB3% NEQ %%J:\ IF %USB4% NEQ %%J:\ IF %USB5% NEQ %%J:\ IF %USB6% NEQ %%J:\ IF %USB7% NEQ %%J:\ IF %USB8% NEQ %%J:\ IF %USB9% NEQ %%J:\ set "USB10=%%J:\"&&GOT USB10F
)
IF %%J==%%J SET USB10=
GOTO DONE

:USB10F
ECHO/ Found HaMaDa USB Drive . . . . . [%USB10%]

:DONE
ECHO/
ECHO/ Search finished . . .
ECHO/

:NOMORE
ECHO/ No More HaMaDa USB Drives Found . . .
ECHO/
GOTO END

:ERROR
ECHO/ Search didn't find any HaMaDa USB Drive plugged in this computer!
ECHO/

:END
ECHO/ (S) Search again.
ECHO/ (Q) Quit
ECHO/
CHOICE /C:QS /N /M " :: Press (S) to search again or (Q) to exit:
IF ERRORLEVEL 2 GOTO START
GOTO EOFF

:EOFF
CLS

ECHO/
ECHO/ SEARCH FINISHED . . .
ECHO/
ECHO/ LIST OF ALL DRIVERs FOUND:
ECHO/
IF "%USB1%"=="" GOTO EOF
ECHO/ 1. HaMaDa USB IN . . . . . . [%USB1%]
IF "%USB2%"=="" GOTO EOF
ECHO/ 2. HaMaDa USB IN . . . . . . [%USB2%]
IF "%USB3%"=="" GOTO EOF
ECHO/ 3. HaMaDa USB IN . . . . . . [%USB3%]
IF "%USB4%"=="" GOTO EOF
ECHO/ 4. HaMaDa USB IN . . . . . . [%USB4%]
IF "%USB5%"=="" GOTO EOF
ECHO/ 5. HaMaDa USB IN . . . . . . [%USB5%]
IF "%USB6%"=="" GOTO EOF
ECHO/ 6. HaMaDa USB IN . . . . . . [%USB6%]
IF "%USB7%"=="" GOTO EOF
ECHO/ 7. HaMaDa USB IN . . . . . . [%USB7%]
IF "%USB8%"=="" GOTO EOF
ECHO/ 8. HaMaDa USB IN . . . . . . [%USB8%]
IF "%USB9%"=="" GOTO EOF
ECHO/ 9. HaMaDa USB IN . . . . . . [%USB9%]
IF "%USB10%"=="" GOTO EOF
ECHO/ 10. HaMaDa USB IN . . . . . . [%USB10%]
PAUSE

:EOF
choice /t 5 /c delay /d d >nul


Report •

Related Solutions


Ask Question