Can someone help me write a batch file?

March 1, 2014 at 18:37:44
Specs: Windows 7
I have about 4000 pdfs that I need to move to existing folders. Both the pdfs and folders begin with 6 numbers. I want the batch to recognize the filename by the first 6 numbers and place the pdf in the folder with the same 6 numbers. The names after the underscore do not have to match only the 6 numbers before the underscore have to match the pdf with the folder. I don’t want to create new files only move the pdfs into existing folders.
Pdf 123456_ABC Company needs to move to folder 123456_Company ABC. Pdfs are in a folder called DLRDOCS on my desktop. The pdfs need to move to DLRFLDS on my desktop.
I want to make a batch file that will move all files/pdfs automatically to the appropriate folders.

See More: Can someone help me write a batch file?

Report •


#1
March 1, 2014 at 19:43:55
http://www.computing.net/answers/pr...

must be something going around...


Report •

#2
March 1, 2014 at 21:04:24
What is set z? Is z representing my DLRDOCS with the pdfs in it or my DLRFLDS where the pdfs are moved to?

What does set z=!z:~0,6! represents mean?


@echo off & setlocal enabledelayedexpansion
for %%a in (*.pdf) do (
set z=%%a
set z=!z:~0,6!


Report •

#3
March 1, 2014 at 21:37:37
I tried this and nothing happened:

@echo off & setlocal enabledelayedexpansion
for %%a in (*.pdf) do (
set z=%%a
set z=!z:~0,6!
if not exist !z! md !z!
move %%a !z!\


Report •

Related Solutions

#4
March 1, 2014 at 21:45:49
My apologies. I gave a brief answer that needed further elaboration. However, your statement/example eludes me:
Pdf 123456_ABC Company needs to move to folder 123456_Company ABC.
Is "Pdf" part of the filename, or just your reference to it? Please, on separate lines, give an exact example of:
complete filename (but no path is needed)
complete subdirectory name (ditto)

I think I get the idea, from your example, but I would appreciate confirmation. (Make up data for the details, but I need the format to be explicit) Meantime hopefully others will get a better grasp.


Report •

#5
March 1, 2014 at 21:50:14
I apologize as well. PDF is not part of the filename.

Filename
123456_ABC Company

Subdirectory name
123456_CompanyABC


Report •

#6
March 1, 2014 at 23:32:59
Ok, good. Are these 6 digits prefix unique? Or is there any possiblity of duplication with different "ABC Company" suffix? If they're unique, it makes things simpler. Here's a trial-balloon, but it's untested, it's late, i'm ready to sleep, etc:

@echo off & setlocal enabledelayedexpansion
for %%a in (*.pdf) do (
set z=%%a
set z=!z:~0,7!
for /D %%b in (!z!*) do echo move %%a %%b\
)
:: === end
it doesn't move the files, because I don't want bad things to happen. See what you think from the output.


Report •

#7
March 4, 2014 at 09:56:14
I have tried everything and my pdfs are only moving to a folder but are not moving specific folders

Report •


Ask Question