Solved

DOS command line programming

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

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 23

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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

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 23

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 23

Expert Comment

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now