Solved

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

Posted on 2008-10-17
9
1,256 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run MS Access Module from Macro / Bat File 9 115
knowing when local account expires (Windows Server OS-DOS) 5 95
SSRS - Powershell 7 80
Odd Coloration 4 44
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 article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…

734 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