Any help on this is appreciated. My DOS use was er...a bit of a while ago.
I would like to use a batch to search C:\folder\folder1 which contains file1.pdf, file1.epub, file1.jpg and potential others
Then " " C:\folder\folder2 " file2.pdf, file2.epub etc. up to folder114
I want to create two master folders one for Epubs and one for pdf's. All other files can be ignored. All pdf's to copy to the pdf folder and the epubs to the Epub folder.
The names of the files can remain the same. I can create the folders ahead of time.
Can anyone assist with a super jump start of the brain here? (that and I want to teach my son something cool lol)
TIA
Gee,
Sort and Copy batch file required
Moderator: DosItHelp
Re: Sort and Copy batch file required
Just set the path to your main folder and the location of the PDFs and Epubs folders, in lines 3, 6 & 7
> Make sure the PDFs and Epubs folders isn't in the main folder where your 114 folder exist.
> The Batch will rename any file that has similar names by adding a number after the file name like this name_[1].ext But if you run the batch again it will just overwrite any existing files in the PDFs and Epubs folders as it won't check if similar names there or not
EDITED
> Make sure the PDFs and Epubs folders isn't in the main folder where your 114 folder exist.
> The Batch will rename any file that has similar names by adding a number after the file name like this name_[1].ext But if you run the batch again it will just overwrite any existing files in the PDFs and Epubs folders as it won't check if similar names there or not
EDITED
Code: Select all
@echo off
:: Create Destination Folders If Not Exist
Set "PDFs=%userprofile%\Desktop\PDFs_Folder"
Set "Epubs=%userprofile%\Desktop\Epubs_Folder"
IF Not Exist "%PDFs%" MD "%PDFs%" 2>nul
IF Not Exist "%Epubs%" MD "%Epubs%" 2>nul
:: Search and Copy PDF and Epub Files
Set "count1=0"
Set "count2=0"
Setlocal EnableDelayedExpansion
For /F "delims=" %%A in ('DIR /B /S /A:-D "*.*"') Do (
:: Process PDF Files
IF /I "%%~xA" equ ".pdf" (
IF Not Exist "%PDFs%\%%~nA%%~xA" (
Copy "%%A" "%PDFs%\*.*" >nul
) Else (
Set /A count1 += 1
Copy "%%A" "%PDFs%\%%~nA[!count1!]%%~xA" >nul
)
)
:: Process Epubs Files
IF /I "%%~xA" equ ".epub" (
IF Not Exist "%Epubs%\%%~nA%%~xA" (
Copy "%%A" "%Epubs%\*.*" >nul
) Else (
Set /A count2 += 1
Copy "%%A" "%Epubs%\%%~nA_[!count2!]%%~xA" >nul
)
)
)
pause
exit /b
Last edited by abc0502 on 16 Dec 2012 02:54, edited 3 times in total.
Re: Sort and Copy batch file required
GeeGee911 wrote:I would like to use a batch to search C:\folder\folder1 which contains file1.pdf, file1.epub, file1.jpg and potential others
Then " " C:\folder\folder2 " file2.pdf, file2.epub etc. up to folder114
I want to create two master folders one for Epubs and one for pdf's. All other files can be ignored. All pdf's to copy to the pdf folder and the epubs to the Epub folder.
Maybe abc0502 has it nailed if you only want two folders, one for epub and one for pdf.
I'm not sure about your requirements: as you mention 114 folders
Re: Sort and Copy batch file required
Actually, after what you said you may be right, i thought she want to have all pdf and all epub files from all 114 folder into just two main folders.
But it also might want to have each one of those 114 folder contain two main folders for pdf and epub files.
But it also might want to have each one of those 114 folder contain two main folders for pdf and epub files.

Re: Sort and Copy batch file required
err...ok maybe I should have used the exact folder names etc...I might have let you up the path a bit here(I doubt anyone other than myself is confused tho lol...
To answer the prev tho, yes, I only want 2 folders at the end of the day, one for epubs and one for pdfs so that my poor only slightly computer literate great grandma can use her the epubs on her ereader and the pdfs on her pc (she's GREAT for her late 80's no???.)
I changed the path in the batch file since I had "hp" instead of "administrators" as the folder...
So then I moved the newfolder to the desktop thinking it was just the destination path but it still wasn't working...SO to simplify and keep the info I give you accurate...I now have
"Newfolder" on the desktop ( C:\Users\HP\Desktop\newfolder ) in which I copied all the 114 folders which contain the various versions of the files.
The batch did create the epub and pdf folders on the desktop as well but they are empty
The batch file is running from within the newfolders folder for sake of ease at the moment - not sure if this matters - but in case...
The actual existing folder names in "newfolder" are "Fine Cooking 001" thru "Fine Cooking 114"
Thanks,
(and me and grandma owe big time)
To answer the prev tho, yes, I only want 2 folders at the end of the day, one for epubs and one for pdfs so that my poor only slightly computer literate great grandma can use her the epubs on her ereader and the pdfs on her pc (she's GREAT for her late 80's no???.)
I changed the path in the batch file since I had "hp" instead of "administrators" as the folder...
So then I moved the newfolder to the desktop thinking it was just the destination path but it still wasn't working...SO to simplify and keep the info I give you accurate...I now have
"Newfolder" on the desktop ( C:\Users\HP\Desktop\newfolder ) in which I copied all the 114 folders which contain the various versions of the files.
The batch did create the epub and pdf folders on the desktop as well but they are empty
The batch file is running from within the newfolders folder for sake of ease at the moment - not sure if this matters - but in case...
The actual existing folder names in "newfolder" are "Fine Cooking 001" thru "Fine Cooking 114"
Thanks,
(and me and grandma owe big time)
Re: Sort and Copy batch file required
This location,
The new folder is your folder that contain all your 114 folder, not he destination folder, any way i changed the code, just make a batch file and place it in the folder that contain your 114 folder then run it.
remember to remove the folders "PDFs_Folder" and "Epubs_Folder" on your desktop from previous run then run the batch.
Set "main=C:\Users\Administrator\Desktop\New folder"
The new folder is your folder that contain all your 114 folder, not he destination folder, any way i changed the code, just make a batch file and place it in the folder that contain your 114 folder then run it.
remember to remove the folders "PDFs_Folder" and "Epubs_Folder" on your desktop from previous run then run the batch.
Re: Sort and Copy batch file required
It's running like a Boss now.
Thanks for all your help. Once I actually read the file I understood 'almost' all of the code!
Grandma reading her new recipes on the iReader thanks you all too.
Cheers.
Thanks for all your help. Once I actually read the file I understood 'almost' all of the code!
Grandma reading her new recipes on the iReader thanks you all too.
Cheers.