Batch to move file based on filename

August 31, 2011 at 07:41:50
Specs: N/A
I'm not very good at programming, so after finding a couple batch doing part of the job, I can't seem to put them together to get the result I need:

We have a folder with thousands of pdf files
Source: D:\scan\orders\2010001.pdf
and they increment up

We would like to have a batch file run once a night and move the files based on the first 3 numbers in the filename.
D:\Archive\200\201\2010001.pdf (up to 2019999)
D:\Archive\300\301 ...

It would be great if the batch could create the folders, but if it's not possible, I could do it manually.
I've seen batch files that could create the second folder(201...299) but they were not made to create the first one (200).

Any kind soul can help me there?
Usualy I can understand what a script does, but I am not good at writing them.
Thank you,

See More: Batch to move file based on filename

Report •

September 8, 2011 at 16:57:23
@echo off
xcopy "c:\foldername\*.*" "d:\target folder\" /d

this will copy all files newer than the ones in the folder or the ones that don't exist

Report •

October 5, 2011 at 12:15:15
thank you for the help, but that's not what I'm looking to do.
We have 1 folder with tons of pdf files
the names of the pdf files are numbers.

I've found this batch file that does part of the job:

@echo off
setlocal EnableDelayedExpansion

cd nameofmyfolder

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set F=%%~Na
set F=!F:~0,3!
if not exist "!F!" md "!F!"
move "%%a" "!F!"
We will then manually move the folders this script created to the right "hundred" folder.
Like the 201, 202, 203 up to 299 folders (generated by the script), to the 200 folder

Report •

Related Solutions

Ask Question