Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to find all the PDF files from the computer and put them into a folder.

So far, I have this:

mkdir d:\test
chcp 65001
FOR /f "tokens=*" %%a in ('dir /s /b  *.pdf') DO copy "%%a" d:\test\
FOR /f "tokens=*" %%a in ('dir /s /b  *.pdf') DO copy "%%a" d:\test\
FOR /f "tokens=*" %%a in ('dir /s /b  *.pdf') DO copy "%%a" d:\test\

For some reason, it doesn't copy everything. In D:, it copied 2126 files out of 2400, and in F: it copied 274 out of 284.

Any ideas why some PDF files aren't being copied and how I can fix it?

share|improve this question

You can count the files and so check for duplicates:

md d:\test 2>nul
set /a count=0
set /a dupli=0
for /r "d:\" %%i in (*.pdf) do (
    if not exist "d:\test\%%~nxi" (
        copy "%%~fi" "d:\test\%%~nxi"
        set /a count+=1
    ) else set /a dupli+=1
echo %count% files copied,  %dupli% not (duplicate files).

Put the target folder in an other drive to avoid copying to itself.

share|improve this answer
Thank you mate for your time ,i run this for the F still the same result it copies only 274 out of 284 as for the D i noticed that the pc does a beep noise for a few seconds also it doesnt copy everything it copies 2126 out of 2481(the numbers are the same as in my program).I forgot a detail which i dont know if its important some of the pdfs dont have english characters, their names are written in another language that's why i put the chcp helped greatly before i put it it wasn't copying around 1200 files with it it doesnt copy around 350 – Psema Apr 1 '13 at 19:44
You need a script, that renames the duplicate files before copying. The chcp shouldn't play a role – Endoro Apr 1 '13 at 19:52
rename them before i start copying or as i do the copy? – Psema Apr 2 '13 at 12:27
You can do it before or you can use a script, that does it automatically. – Endoro Apr 2 '13 at 12:31

Not having alot of details, my first guess would be that there are duplicate file names. Copy in a acript will not prompt for overwrite and will skip the file.

share|improve this answer
The thing is i want even the duplicates cause in some cases its different pdf with the same name for example 1.pdf its common – Psema Apr 2 '13 at 8:18
As this is the case, Endoo provided a great starting point. When you detect that there is a dupliate, you will need a scripted process to copy as a new unique file name. If you have many files with the same name, make sure the process really chooses a unique name or re-checks for an existing file with the same name (with a loop perhaps). – YLearn Apr 2 '13 at 13:33

I suspect this happens because you're not in the right folder when executing the FOR command.



just changes the drive, but not the directory. If the last used directory of the D drive was D:\Example, there's where the command takes you.

There are three ways to fix this:

  • Execute

    CD \

    before the FOR command.

  • Execute

    CD /D D:\

    before the FOR command.

  • Specify the drive and directory in the FOR command itself:

    FOR /F "tokens=*" %%A in ('DIR /S /B  D:\*.pdf') DO COPY "%%A" D:\test\
share|improve this answer
Thank you for your help mate but unfortunately nothing changed still the same result with all the 3 ways :( – Psema Apr 1 '13 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.