File finder help
Moderator: DosItHelp
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
File finder help
I just need a little more help with this one. I need to replace all of the -------- with code that will search the computer for the files then copy them to the usb drive. Any help would be greatly appreciated.
here is the code.
Start
:back
@echo off
:start
cls
echo 1 Locate all docx files
echo 2 Locate all jpg files
echo 3 Locate all pptx files
echo 4 Locate all xlsx files
echo 5 Locate all txt files
echo 6 Exit
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
cls
@echo off
echo a docx
echo b doc
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto docx1
if "%userinp%"=="b" goto doc2
if "%userinp%"=="c" goto back
:docx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydocx
if "%userinp%"=="b" goto 1
:doc2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydoc
if "%userinp%"=="b" goto 1
goto end
:copydocx
-----------
:copydoc
-----------
:2
cls
@echo off
echo a docx
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto jpg
if "%userinp%"=="b" goto back
:jpg
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyjpg
if "%userinp%"=="b" goto 2
goto end
:copyjpg
-----------
:3
cls
@echo off
echo a pptx
echo b ppt
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto pptx1
if "%userinp%"=="b" goto ppt2
if "%userinp%"=="c" goto back
:pptx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copypptx
if "%userinp%"=="b" goto 3
:copypptx
----------
:ppt2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyppt
if "%userinp%"=="b" goto 3
:copyppt
------------
goto end
:4
cls
@echo off
echo a xlsx
echo b xls
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto xlsx1
if "%userinp%"=="b" goto xls2
if "%userinp%"=="c" goto back
lsx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxlsx
if "%userinp%"=="b" goto 4
:copyxlsx
-------------
ls2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxls
if "%userinp%"=="b" goto 4
:copyxls
--------------
goto end
:5
cls
@echo off
echo a txt
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto txt1
if "%userinp%"=="b" goto back
:txt1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copytxt
if "%userinp%"=="b" goto 5
:copytxt
--------------
goto end
:6
cls
exit
stuff
goto end
:end
pause>nul
End of Code
here is the code.
Start
:back
@echo off
:start
cls
echo 1 Locate all docx files
echo 2 Locate all jpg files
echo 3 Locate all pptx files
echo 4 Locate all xlsx files
echo 5 Locate all txt files
echo 6 Exit
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
cls
@echo off
echo a docx
echo b doc
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto docx1
if "%userinp%"=="b" goto doc2
if "%userinp%"=="c" goto back
:docx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydocx
if "%userinp%"=="b" goto 1
:doc2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydoc
if "%userinp%"=="b" goto 1
goto end
:copydocx
-----------
:copydoc
-----------
:2
cls
@echo off
echo a docx
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto jpg
if "%userinp%"=="b" goto back
:jpg
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyjpg
if "%userinp%"=="b" goto 2
goto end
:copyjpg
-----------
:3
cls
@echo off
echo a pptx
echo b ppt
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto pptx1
if "%userinp%"=="b" goto ppt2
if "%userinp%"=="c" goto back
:pptx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copypptx
if "%userinp%"=="b" goto 3
:copypptx
----------
:ppt2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyppt
if "%userinp%"=="b" goto 3
:copyppt
------------
goto end
:4
cls
@echo off
echo a xlsx
echo b xls
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto xlsx1
if "%userinp%"=="b" goto xls2
if "%userinp%"=="c" goto back
lsx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxlsx
if "%userinp%"=="b" goto 4
:copyxlsx
-------------
ls2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxls
if "%userinp%"=="b" goto 4
:copyxls
--------------
goto end
:5
cls
@echo off
echo a txt
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto txt1
if "%userinp%"=="b" goto back
:txt1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copytxt
if "%userinp%"=="b" goto 5
:copytxt
--------------
goto end
:6
cls
exit
stuff
goto end
:end
pause>nul
End of Code
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
Code: Select all
@echo off
setlocal enableextensions
set "drive=c:"
set "stick=z:"
set "ext=docx"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
title Copying "%%f"
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
title All %3s copied
Prepare to multiple situations with the same file names. You can automatically overwrite files over with a key COPY /Y.
But the files can be really different. The best option will automatically rename the new files.
Last edited by !k on 08 Jan 2010 02:40, edited 1 time in total.
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
Thanks for replying. I am new to ms dos so sorry if I don't get it right away.
But what is it exactly does the code do, and how do I implement it into the code I already have?
@echo off
setlocal enableextensions
set "drive=c:"
set "stick=z:"
set "ext=docx"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
But what is it exactly does the code do, and how do I implement it into the code I already have?
@echo off
setlocal enableextensions
set "drive=c:"
set "stick=z:"
set "ext=docx"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
Your end:
replace to:
End of Code
And call
Untested
Code: Select all
goto end
:end
pause>nul
replace to:
Code: Select all
goto end
:end
pause>nul
exit /b
:ext2usb
setlocal enableextensions
set "drive=%1"
set "stick=%2"
set "ext=%3"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
title Copying "%%f"
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
title All %3s copied
endlocal
goto :eof
And call
Code: Select all
:copydocx
call :ext2usb c: z: docx
call :ext2usb d: z: docx
:copydoc
call :ext2usb c: z: doc
call :ext2usb d: z: doc
Untested
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
So I think I did something wrong beacuse its not working my code now is this:
:back
@echo off
:start
cls
echo 1 Locate all docx files
echo 2 Locate all jpg files
echo 3 Locate all pptx files
echo 4 Locate all xlsx files
echo 5 Locate all txt files
echo 6 Exit
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
cls
@echo off
echo a docx
echo b doc
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto docx1
if "%userinp%"=="b" goto doc2
if "%userinp%"=="c" goto back
:docx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydocx
if "%userinp%"=="b" goto 1
:doc2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydoc
if "%userinp%"=="b" goto 1
goto end
:copydocx
call :ext2usb c: z: docx
call :ext2usb d: z: docx
goto end
:copydoc
call :ext2usb c: z: doc
call :ext2usb d: z: doc
:2
cls
@echo off
echo a docx
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto jpg
if "%userinp%"=="b" goto back
:jpg
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyjpg
if "%userinp%"=="b" goto 2
goto end
:copyjpg
call :ext2usb c: z: jpg
call :ext2usb d: z: jpg
goto end
:3
cls
@echo off
echo a pptx
echo b ppt
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto pptx1
if "%userinp%"=="b" goto ppt2
if "%userinp%"=="c" goto back
:pptx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copypptx
if "%userinp%"=="b" goto 3
:ppt2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyppt
if "%userinp%"=="b" goto 3
:copypptx
call :ext2usb c: z: pptx
call :ext2usb d: z: pptx
goto end
:copyppt
call :ext2usb c: z: ppt
call :ext2usb d: z: ppt
goto end
:4
cls
@echo off
echo a xlsx
echo b xls
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto xlsx1
if "%userinp%"=="b" goto xls2
if "%userinp%"=="c" goto back
lsx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxlsx
if "%userinp%"=="b" goto 4
ls2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxls
if "%userinp%"=="b" goto 4
:copyxlsx
call :ext2usb c: z: docx
call :ext2usb d: z: docx
goto end
:copyxls
call :ext2usb c: z: xls
call :ext2usb d: z: xls
goto end
:5
cls
@echo off
echo a txt
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto txt1
if "%userinp%"=="b" goto back
:txt1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copytxt
if "%userinp%"=="b" goto 5
:copytxt
call :ext2usb c: z: txt
call :ext2usb d: z: txt
goto end
:6
cls
exit
stuff
goto end
:end
pause>nul
exit /b
:ext2usb
setlocal enableextensions
set "drive=%1"
set "stick=%2"
set "ext=%3"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
title Copying "%%f"
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
title All %3s copied
endlocal
goto :eof
:back
@echo off
:start
cls
echo 1 Locate all docx files
echo 2 Locate all jpg files
echo 3 Locate all pptx files
echo 4 Locate all xlsx files
echo 5 Locate all txt files
echo 6 Exit
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
cls
@echo off
echo a docx
echo b doc
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto docx1
if "%userinp%"=="b" goto doc2
if "%userinp%"=="c" goto back
:docx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydocx
if "%userinp%"=="b" goto 1
:doc2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copydoc
if "%userinp%"=="b" goto 1
goto end
:copydocx
call :ext2usb c: z: docx
call :ext2usb d: z: docx
goto end
:copydoc
call :ext2usb c: z: doc
call :ext2usb d: z: doc
:2
cls
@echo off
echo a docx
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto jpg
if "%userinp%"=="b" goto back
:jpg
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyjpg
if "%userinp%"=="b" goto 2
goto end
:copyjpg
call :ext2usb c: z: jpg
call :ext2usb d: z: jpg
goto end
:3
cls
@echo off
echo a pptx
echo b ppt
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto pptx1
if "%userinp%"=="b" goto ppt2
if "%userinp%"=="c" goto back
:pptx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copypptx
if "%userinp%"=="b" goto 3
:ppt2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyppt
if "%userinp%"=="b" goto 3
:copypptx
call :ext2usb c: z: pptx
call :ext2usb d: z: pptx
goto end
:copyppt
call :ext2usb c: z: ppt
call :ext2usb d: z: ppt
goto end
:4
cls
@echo off
echo a xlsx
echo b xls
echo c back
set /p userinp=choose an option(a,b,c)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto xlsx1
if "%userinp%"=="b" goto xls2
if "%userinp%"=="c" goto back
lsx1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxlsx
if "%userinp%"=="b" goto 4
ls2
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copyxls
if "%userinp%"=="b" goto 4
:copyxlsx
call :ext2usb c: z: docx
call :ext2usb d: z: docx
goto end
:copyxls
call :ext2usb c: z: xls
call :ext2usb d: z: xls
goto end
:5
cls
@echo off
echo a txt
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto txt1
if "%userinp%"=="b" goto back
:txt1
cls
echo a copy to the usb drive
echo b back
set /p userinp=choose an option(a,b)
set userinp=%userinp:~0,1%
if "%userinp%"=="a" goto copytxt
if "%userinp%"=="b" goto 5
:copytxt
call :ext2usb c: z: txt
call :ext2usb d: z: txt
goto end
:6
cls
exit
stuff
goto end
:end
pause>nul
exit /b
:ext2usb
setlocal enableextensions
set "drive=%1"
set "stick=%2"
set "ext=%3"
if not exist "%stick%\%ext%" mkdir "%stick%\%ext%"
for /f "delims=" %%f in ('dir %drive%\*.%ext% /a-d/b/s/od') do (
title Copying "%%f"
copy /b /y "%%f" "%stick%\%ext%\%%~nxf" >nul
)
title All %3s copied
endlocal
goto :eof
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
"%~dp0" is equal "disc:\path\" so call
or edit :ext2usb subprogram
Code: Select all
call :ext2usb c: %~d0 docx
or edit :ext2usb subprogram