Solved

DOS command line programming

Posted on 2015-01-29
9
71 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Difference between List and Array in Python 5 142
Developing a front end to SPLUNK 1 106
Create .bat File 16 94
Code planning methods/tools? 5 56
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 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