Computer Hope

Microsoft => Microsoft DOS => Topic started by: widetree on April 20, 2017, 03:59:27 AM

Title: finding/moving files
Post by: widetree on April 20, 2017, 03:59:27 AM
Good Morning

Could someone tell me what the dos cmd is to find all pdf files in all sub directories and copy them to a named folder please.

Thank you

Title: Re: finding/moving files
Post by: Hackoo on April 20, 2017, 04:39:36 AM
Good Morning

Could someone tell me what the dos cmd is to find all pdf files in all sub directories and copy them to a named folder please.

Thank you
Hi  ;)
Did you mean move or copy them in new folder ?
Title: Re: finding/moving files
Post by: widetree on April 20, 2017, 05:21:57 AM
To copy please
Title: Re: finding/moving files
Post by: Hackoo on April 20, 2017, 06:59:51 AM
Hi  :)
You can give a try with this batch file : CopyPDF.bat
Just copy and paste this code with your notepad and save it as CopyPDF.bat and just drag and drop your folder on it. ;)

Code: [Select]
@echo off
Title Copying All PDF files in folder and its subfolders with drag and drop
Mode con cols=75 lines=3 & color 0E
set "Drag_Dir=%~1"
set "Ext=pdf"
echo(
IF ["%Drag_Dir%"] EQU [""] Goto:Error
set "newFolder=%Drag_Dir%\New_%Ext%_Folder"
Rem Create the new folder to copy all *.pdf on it
If not exist "%newFolder%" md "%newFolder%"
2>nul cd "%newFolder%" && Call :CopyPDFfiles || Goto:Error
EXplorer "%newFolder%"
Exit
::********************************************
:CopyPDFfiles
for /f "delims=" %%I in ('Dir /a-d /b /s "%Drag_Dir%\*.%Ext%"') do (
    Copy /Y "%%I" "%newFolder%"
)
Exit /b
::********************************************
:Error
Mode con cols=75 lines=5 & Color 0C
echo(
ECHO           You must drag and drop a folder on this batch program
ECHO                 to copy all PDF files in new location
Timeout /T 10 /NoBreak >nul
Exit /b
::*****************************************
Title: Re: finding/moving files
Post by: widetree on April 20, 2017, 07:41:51 AM
Thank you Hacko.

It created the folder but no pdf's inside it.
Title: Re: finding/moving files
Post by: Hackoo on April 20, 2017, 07:49:12 AM
It created the folder but no pdf's inside it.
Check if your folder and its subfolders contains any pdf files or not !
if the batch file dosen't find any pdf files it create an empty folder named New_PDF_Folder
Title: Re: finding/moving files
Post by: widetree on April 20, 2017, 08:13:16 AM
Yes that worked beautifully! Thank you very much! Could you possibly tweet the code so I could run this batch file to find pdf's with a name containing the characters "plan"?
Title: Re: finding/moving files
Post by: Hackoo on April 20, 2017, 08:36:18 AM
Yes that worked beautifully! Thank you very much! Could you possibly tweet the code so I could run this batch file to find pdf's with a name containing the characters "plan"?
Here we go  ;)
Code: [Select]
@echo off
Title Copying All PDF files in folder and its subfolders with drag and drop
Mode con cols=75 lines=3 & color 0E
set "Drag_Dir=%~1"
set "Ext=pdf"
set "Word=plan"
IF ["%Drag_Dir%"] EQU [""] Goto:Error
set "newFolder=%Drag_Dir%\New_%Ext%_Folder"
Rem Create the new folder to copy all *.pdf on it
If not exist "%newFolder%" md "%newFolder%"
2>nul cd "%newFolder%" && Call :CopyPDFfiles || Goto:Error
Explorer "%newFolder%"
Exit
::********************************************
:CopyPDFfiles
for /f "delims=" %%I in ('Dir /a-d /b /s "%Drag_Dir%\*.%Ext%" ^| find /I "%Word%"') do (
Rem find all pdf's with a name containing the characters "plan" and copy them to the newfolder
    Copy /Y "%%I" "%newFolder%"
)
Exit /b
::********************************************
:Error
Mode con cols=75 lines=5 & Color 0C
echo(
ECHO           You must drag and drop a folder on this batch program
ECHO                 to copy all PDF files in new location
Timeout /T 10 /NoBreak >nul
Exit /b
::*****************************************
Title: Re: finding/moving files
Post by: widetree on April 21, 2017, 12:14:51 AM
That worked too! Thank you so much! I did not realise so much coding was involved.
Title: Re: finding/moving files
Post by: Hackoo on April 21, 2017, 04:14:29 AM
That worked too! Thank you so much! I did not realise so much coding was involved.
You are welcome dude and don't forget to use the Thanks link  ;D
Have a nice day !  ;)