File finder help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

File finder help

#1 Post by The Great One » 05 Jan 2010 00:13

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
:xlsx1
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
-------------

:xls2
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

The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

#2 Post by The Great One » 06 Jan 2010 23:08

Is anyone gonna help me please? :cry:
I can locate all the files with --Dir *.docx /s-- but then how do i copy all of them? Any help will be appreciated.

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

#3 Post by !k » 07 Jan 2010 02:58

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.

The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

#4 Post by The Great One » 08 Jan 2010 00:45

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
)

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

#5 Post by !k » 08 Jan 2010 02:35

Your end:

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
End of Code

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

The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

#6 Post by The Great One » 12 Jan 2010 17:36

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
:xlsx1
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
:xls2
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

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

#7 Post by !k » 12 Jan 2010 17:46

Changed z: to present the letter of your usb-stick

The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

#8 Post by The Great One » 12 Jan 2010 22:22

If I want to use this on multipul computers can the Z be changed to "%~dp0"

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

#9 Post by !k » 12 Jan 2010 23:23

"%~dp0" is equal "disc:\path\" so call

Code: Select all

call :ext2usb c: %~d0 docx

or edit :ext2usb subprogram

Post Reply