Solved

cannot make it run as a batch file

Posted on 2013-01-15
3
262 Views
Last Modified: 2013-01-15
I am able to run the following from the command prompt with success, but I cannot make it run as a batch file any help making this run from a .bat file is appreciated

CD /D "D: \PDFBills"
set "source=D: \PDFBills\UnZip"
set "targetRoot=D:\ PDFBills\MonthlyPDFBills"
for %F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %A in ("%~tF") do (
    if not exist "%targetRoot%\%C\%A" mkdir "%targetRoot%\%C\%A"
    move "%~fF" "%targetRoot%\%C\%A"
  )
)

Lori
0
Comment
Question by:NLITech
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 38780916
You have a space in the source/dest line for starters, but most of all any % syntax within for commands need to be doubled to %% in batch files.  Try this for starters.

Steve

@echo off
CD /D "D:\PDFBills"
set source=D:\PDFBills\UnZip
set targetRoot=D:\PDFBills\MonthlyPDFBills
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    if not exist "%targetRoot%\%%C\%%A" mkdir "%targetRoot%\%%C\%%A"
    move "%%~fF" "%targetRoot%\%%C\%%A"
  )
)

Open in new window


Steve
0
 

Author Closing Comment

by:NLITech
ID: 38780944
Perfect! Thank you.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38781502
no problem
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now