Solved

DOS command line programming

Posted on 2015-01-29
9
72 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
Independent Software Vendors: 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

628 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