?
Solved

Help with MS-DOS Syntax for Using Quotation Marks Within Quotation Marks

Posted on 2008-10-17
9
Medium Priority
?
1,273 Views
Last Modified: 2010-04-21
I'm trying to create a host of folders in one of our network drives at our firm.  I've discovered and have studied the use of forfiles.exe, and almost have what I need.  The following command is very close to accomplishing my task:
forfiles /p c:\test /c "cmd /c if @isdir==TRUE md @PATH\TY08\Tax_Returns"
It will create a subdirectory for every folder in c:\test named TY08, and also creates a folder in TY08 called Tax_Returns.  I've only included the underscore because I can't get it to use a space.  I'm aware that I would normally use a command like md @path\TY08\"Tax Returns" with the quotations and it would spit out the right new folder name.  But since I have to have quotations around the entire command section, how can I imbed a second layer of quotations that MS-DOS will read?  I've tried this to no avail:
forfiles /p c:\test /c "cmd /c if @isdir==TRUE md @PATH\TY08\""Tax Returns"""

Ideas appreciated.  Is there a better way to put together a batch file command to create subdirectories?
0
Comment
Question by:bruderbell
[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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:Goofytouy
ID: 22743774

Hi bruderbell, use simple quotation marks (apostrophe)  as in:

forfiles /p c:\test /c "cmd /c if @isdir==TRUE md '@PATH\TY08\Tax_Returns'"

or

forfiles /p c:\test /c 'cmd /c if @isdir==TRUE md "@PATH\TY08\Tax_Returns"'

Regards
Goofy
0
 
LVL 5

Expert Comment

by:Goofytouy
ID: 22743781

Note that it's   ' and not ´ (tilde)


regards
Goofy
0
 

Author Comment

by:bruderbell
ID: 22743842
Goofytouy:
Hi bruderbell, use simple quotation marks (apostrophe)  as in:

forfiles /p c:\test /c "cmd /c if @isdir==TRUE md '@PATH\TY08\Tax_Returns'"

or

forfiles /p c:\test /c 'cmd /c if @isdir==TRUE md "@PATH\TY08\Tax_Returns"'

Regards
Goofy

Thanks for the quick response.  Unfortunately, when I just tried the first option I created folders named TY08'Source Documents' in the TY08 Folder.
The second option failed to create any new folders.
Any other ideas?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:bruderbell
ID: 22743922
Ok, sorry about that.  The command that created the TY08'Source Documents' folders was:
forefiles /p c:\test /c "cmd /c if @isdir==TRUE md @path\TY08\'Tax Returns'"

However, when entered as you suggested (forfiles /p c:\test /c "cmd /c if @isdir==TRUE md '@PATH\TY08\Tax_Returns'") it didn't create any folders.  I had it echo out the resultant command to a file (forfiles /p c:\test /c "cmd /c if @isdir==TRUE echo md '@PATH\TY08\Source Documents'" > c:\file.txt) and this is the command it was trying to execute:

md '"c:\test\1"\TY08\Source Documents'

Please note that I can successfully create the folders with the underscore but am trying to create the names with a space.  

0
 
LVL 1

Expert Comment

by:cristides
ID: 22743963
You can't create a folder with space on cmd. If you want to do that you can do on poowershell
0
 

Author Comment

by:bruderbell
ID: 22743980
cristides:
You can't create a folder with space on cmd. If you want to do that you can do on poowershell

How would I do that?
0
 
LVL 1

Expert Comment

by:cristides
ID: 22744041
Hi,
you must to install power shell from microsoft and to change your script :
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx 
Here you find a link how to download powershell and some examples.
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 1200 total points
ID: 22744052
Escape the quotes using backslashes.  Also, when using paths with spaces you always put quotes around the entire path including the parent directories.


forfiles /p c:\test /c "cmd /c if @isdir==TRUE md \"@PATH\TY08\Tax Returns\""

Open in new window

0
 

Author Closing Comment

by:bruderbell
ID: 31507235
Beautiful solution!  This is exactly what I needed, and the code snippet performed the exact function I'd requested.  Somebody else claimed it couldn't be done, but I thought it must be possible.  Thanks!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

764 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