Solved

cannot make it run as a batch file

Posted on 2013-01-15
3
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

697 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