Solved

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

Posted on 2008-10-17
9
1,262 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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