Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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