Solved

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

Posted on 2008-10-17
9
1,225 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
  • 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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 300 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

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

9 Experts available now in Live!

Get 1:1 Help Now