• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

cannot make it run as a batch file

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
NLITech
Asked:
NLITech
  • 2
1 Solution
 
Steve KnightIT ConsultancyCommented:
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
 
NLITechAuthor Commented:
Perfect! Thank you.
0
 
Steve KnightIT ConsultancyCommented:
no problem
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now