Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DOS command line programming

Posted on 2015-01-29
9
Medium Priority
?
74 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
  • 6
  • 3
9 Comments
 
LVL 25

Assisted Solution

by:NVIT
NVIT earned 2000 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 25

Accepted Solution

by:
NVIT earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 25

Assisted Solution

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

Assisted Solution

by:NVIT
NVIT earned 2000 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 25

Expert Comment

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

Assisted Solution

by:NVIT
NVIT earned 2000 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

926 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