Solved batch move pdf files

June 26, 2015 at 06:41:05
Specs: Windows 7
how can i move existing pdf files based on the file name to folder

Example : i have the pdf file as 4112587 week 25.pdf

this should be moved to an existing folder as 4112587 based ont eh first 7 characters of the file

if the file already exists in the folder leave th file in the original folder

See More: batch move pdf files

Report •

June 26, 2015 at 19:27:17
Destination folder name and filename are is ambiguous (to me). Folder named 4112587 (for exammple)? or just "some folder whatever". File keeps full name? or renamed to the truncation (first seven). I guess the folder name is the first seven, and the filename stays the same.
::------ begin batch snippet
for /f "tokens=1-3" %%a in ('dir /a-d *.pdf') do (
if not exist %%a\ "%%a %%b %%c.pdf" move "%%a %%b %%c.pdf" %%a
::------ end snippet - not tested! rough draft!

message edited by nbrane

Report •

June 27, 2015 at 03:40:55
I have filenames as 4112587 week 1.pdf, 4112587 week 2.pdf etc all the files which has 4112587 should be moved to an existing folder as 4112587. Hope I am clear

Report •

June 27, 2015 at 20:47:56
✔ Best Answer
Then it should work! But run tests first, since this IS a "move" and not a copy.

Report •

Related Solutions

June 29, 2015 at 00:50:08
Sorry for the late reply as i had to test this at work.. couldn't try this over the weekend.. do i have to change anything in the code.. as it is not working I have a file name "4111025 uke 25.pdf" this should be moved to Folder named "4111025" ( existing folder).

Do I have to change directory name ("'dir /a-d *.pdf'")

message edited by oodai

Report •

June 29, 2015 at 08:19:59
I have tried with the below code, the challange is every file is moving to the first folder rather than reading first 7 character of the file name

@echo on
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in ('dir /a-d /b *') do (
set filename=%%1&set dirname=!filename:~0,4!

for /f "tokens=*" %%A in ('dir /ad /b') do (
set dirid=%%A&set dirid=!dirid:~0,4!

if "!dirid!" equ "!dirname!" move %%1 %%A

Report •

Ask Question