Solved

DOS command line programming

Posted on 2015-01-29
9
68 Views
Last Modified: 2015-10-08
I have a file folder structure (S:\CLIENTS\A\clientname).
Note: there are numerous clientnames in the folder.
I want to add another sub-folder under each clientname, 2014.

I'd like to know the DOS commands to input (at a DOS prompt) to do such a task.

Thanks
0
Comment
Question by:vdaigle
[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
  • 6
  • 3
9 Comments
 
LVL 24

Assisted Solution

by:NVIT
NVIT earned 500 total points
ID: 40578173
set dmain=S:\CLIENTS\A
for /d %%a in (%dmain%\*.*) do (
  md "%%a\2014"
)

Or, on one line...
for /d %%a in (S:\CLIENTS\A\*.*) do (md "%%a\2014")
0
 

Author Comment

by:vdaigle
ID: 40578221
One line command did not work. I typed S:> for /d %%a in (S:Clients\A\*.*) do (md "%%a\2014").
This returned a message: "%%a was unexpected at this time".
0
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40578227
If you're running the line on the CMD prompt, please change it to...
for /d %a in (S:\CLIENTS\A\*.*) do (md "%a\2014")
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vdaigle
ID: 40578472
OK; this worked.
Now a follow on since we have this working.
What would the input be if instead of the folder S:\Clients\A it was S:\Crown City Financial Services\Clients\A?

When I input this name string DOS treats Crown as a folder, City as a folder, Financial as a folder and Services as a folder!
What is the DOS command to treat Crown City Financial Services as one name/folder?

Thanks
0
 
LVL 24

Assisted Solution

by:NVIT
NVIT earned 500 total points
ID: 40578476
Try...
for /d %a in ("S:\Crown City Financial Services\Clients\A\*.*") do (md "%a\2014")
0
 
LVL 24

Assisted Solution

by:NVIT
NVIT earned 500 total points
ID: 40578528
If you'd like to use this in the future, without changing the folder name manually each time, one way is to make a .bat file
- Run notepad
- Select All this code, copy and paste this into notepad...
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

if (%1) equ () (
  echo "%0" missing folder name
  REM Pause 5 seconds
  ping 127.0.0.1 -n 5 >nul
  goto :eof
) else (
  for /d %%a in ("%1\*") do (
    set PName=%%~a
    md "!PName!\2014"
  )
)

Open in new window

- Save notepad to somewhere you'll see it, e.g. your Desktop.
- Save it to a name like Make2014Dirs.bat
- When you want to use it, open Windows Explorer to the folder you want to affect
- Drag the folder name onto Make2014Dirs.bat
0
 

Author Comment

by:vdaigle
ID: 40578680
Try...
for /d %a in ("S:\Crown City Financial Services\Clients\A\*.*") do (md "%a\2014")

This input returned, "More?"  (without the " ")

Created the Batch file and dragged the folder to it BUT it treated each word in the folder name as a separate folder.
For example, it created a folder named Crown with 2014 subfolder; a folder named City with a 2014 subfolder, etc.
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40578695
Please post the code you copied.
0
 
LVL 24

Assisted Solution

by:NVIT
NVIT earned 500 total points
ID: 40580526
@echo off
REM --------------------------------------
REM Version 2
SETLOCAL ENABLEDELAYEDEXPANSION

set SecPause=5
if (%1) equ () (
  echo "%0" missing folder name
  REM Pause 5 seconds
  ping 127.0.0.1 -n %SecPause% >nul
  goto :eof
) else (
  call :DoIt %1
  echo Done
  REM Pause 5 seconds
  ping 127.0.0.1 -n %SecPause% >nul
  goto :eof
)

:DoIt
set PN=%~1
REM echo PN=%PN%
for /d %%a in ("%PN%\*") do (
  set PName=%%~a
  REM if not exist "!PName!\2014" md "!PName!\2014"
  if not exist "!PName!\2014" (
    md "!PName!\2014"
    if %errorlevel% equ 0 (
      echo Successfully made folder "!PName!\2014"
    ) else (
      echo Failed making folder "!PName!\2014"
    )
  ) else (
    echo "!PName!\2014" already exists
  )
)

Open in new window

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

740 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