0

I am using this code to move pdf files from the folder "PDF" to "PDF\old"

C:\WINDOWS\system32\cmd.exe /c "for /r c:\Users\ADMIN\Desktop\PDF\ %f in (*.pdf) do @move "%f" c:\Users\ADMIN\Desktop\PDF\old"

however, when there's a subfolder ("PDF\sub") with more PDFs, they will get moved to the folder "PDF\old" too - can the command be restricted to exclude any subfolders?

Thanks a lot

teaspoon
  • 115
  • 1
  • 1
  • 12

2 Answers2

2

I think this is what you mean when you say exclude subfolders?

for /f "delims=*" %F in ('dir /b "C:\users\admin\desktop\pdf\*.pdf"') do @move "%F" "c:\users\admin\desktop\pdf\old"

Also, this answer to a related question might be of interest to you.

Hydranix
  • 328
  • 3
  • 10
  • Thanks, this works too. Funny enough, though, it is Case-sensitive. Also, due to some bug, when I was in the destination folder in Total Commander (the active window), the files wouldn't copy... – teaspoon Mar 24 '18 at 10:07
2

I think you are doing it too complex.

Moving all pdf files to another folder - the easiest way:

move "c:\Users\ADMIN\Desktop\PDF\*.pdf" "c:\Users\ADMIN\Desktop\PDF\old"
tukan
  • 17,050
  • 1
  • 20
  • 48
  • of course, why was I doing it the difficult way? Thanks :-) – teaspoon Mar 24 '18 at 10:05
  • @teaspoon you are welcome. Well the point of loops is to do something in or with subfolders and/or files within them. For simple operations like yours it is overkill. For such tasks it is best to use command line commands created for that. – tukan Mar 24 '18 at 16:03