Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to create directory in SQL with Space

How to create directory in SQL with Space

Scheduled Pinned Locked Moved Database
helpdatabasetutorial
12 Posts 6 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Quinn

    Surround the directory string with double quotes

    ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

    S Offline
    S Offline
    Samarjeet Singh india
    wrote on last edited by
    #3

    Thank you very much for your reply but I already did as Exec master.dbo.xp_cmdshell '"C:\Temp\My Test "' but still getting facing problem

    Samar

    1 Reply Last reply
    0
    • S Samarjeet Singh india

      Hello, I am able to create a directory by using sql as Exec master.dbo.xp_cmdshell 'C:\MyTest\<>' but when I tried to create director name with space as Exec master.dbo.xp_cmdshell 'C:\My Test'\<> then its throwing error. can anybody please help me how to create directory with space in SQL

      Samar

      T Offline
      T Offline
      thatraja
      wrote on last edited by
      #4

      Samarjeet Singh@india wrote:

      Exec master.dbo.xp_cmdshell 'C:\My Test'\<<DATE>> then its throwing error.

      What's that? always include those details in your question.

      thatraja

      Please update this article Useful Reference Books, it's urgent for Q/A section

      S 1 Reply Last reply
      0
      • T thatraja

        Samarjeet Singh@india wrote:

        Exec master.dbo.xp_cmdshell 'C:\My Test'\<<DATE>> then its throwing error.

        What's that? always include those details in your question.

        thatraja

        Please update this article Useful Reference Books, it's urgent for Q/A section

        S Offline
        S Offline
        Samarjeet Singh india
        wrote on last edited by
        #5

        For example if I tried to run in sql Exec master.dbo.xp_cmdshell '"C:\Temp\My Test"' Then I am getting following 3 rows of messages 1- 'C:\Temp\My' is not recognized as an internal or external command 2-operable program or batch file. 3- NULL Thanks

        1 Reply Last reply
        0
        • S Samarjeet Singh india

          Hello, I am able to create a directory by using sql as Exec master.dbo.xp_cmdshell 'C:\MyTest\<>' but when I tried to create director name with space as Exec master.dbo.xp_cmdshell 'C:\My Test'\<> then its throwing error. can anybody please help me how to create directory with space in SQL

          Samar

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #6

          You need to use xp_create_subdir, not xp_cmd_shell: http://www.mssqltips.com/sqlservertip/1460/sql-server-script-to-create-windows-directories/[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          S 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            You need to use xp_create_subdir, not xp_cmd_shell: http://www.mssqltips.com/sqlservertip/1460/sql-server-script-to-create-windows-directories/[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            S Offline
            S Offline
            Samarjeet Singh india
            wrote on last edited by
            #7

            Thank u very much !!!!! its working in sql2008 but client is running in older version(Sql2000) and in older version its unable to find the reference and producing following msg

            Server: Msg 2812, Level 16, State 62, Line 1
            Could not find stored procedure 'master.dbo.xp_create_subdir'.

            is any other method so that its working in SQL2000 as well Thanks in advance

            Richard DeemingR 1 Reply Last reply
            0
            • S Samarjeet Singh india

              Thank u very much !!!!! its working in sql2008 but client is running in older version(Sql2000) and in older version its unable to find the reference and producing following msg

              Server: Msg 2812, Level 16, State 62, Line 1
              Could not find stored procedure 'master.dbo.xp_create_subdir'.

              is any other method so that its working in SQL2000 as well Thanks in advance

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #8

              For SQL 2000, you'll need to stick with xp_cmdshell, but you need to put mkdir in front of the path you want to create:

              Exec master.dbo.xp_cmdshell 'mkdir "C:\My Test\<>"'

              http://www.sqlservercentral.com/Forums/Topic604168-8-1.aspx[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              S 1 Reply Last reply
              0
              • S Samarjeet Singh india

                Hello, I am able to create a directory by using sql as Exec master.dbo.xp_cmdshell 'C:\MyTest\<>' but when I tried to create director name with space as Exec master.dbo.xp_cmdshell 'C:\My Test'\<> then its throwing error. can anybody please help me how to create directory with space in SQL

                Samar

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #9

                You might want to tell everyone that SQL 2000 is well past the end of life - including extended support. http://support.microsoft.com/lifecycle/search/?sort=PN&alpha=SQL[^]

                1 Reply Last reply
                0
                • S Samarjeet Singh india

                  Hello, I am able to create a directory by using sql as Exec master.dbo.xp_cmdshell 'C:\MyTest\<>' but when I tried to create director name with space as Exec master.dbo.xp_cmdshell 'C:\My Test'\<> then its throwing error. can anybody please help me how to create directory with space in SQL

                  Samar

                  M Offline
                  M Offline
                  Minghao Xue
                  wrote on last edited by
                  #10

                  below procedure should be the solution create procedure sp_create_directory ( @full_path varchar(500) ) as set nocount on declare @command varchar(1000) set @command = 'mkdir ' + @full_path exec master..xp_cmdshell @command , no_output set nocount off GO

                  S 1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    For SQL 2000, you'll need to stick with xp_cmdshell, but you need to put mkdir in front of the path you want to create:

                    Exec master.dbo.xp_cmdshell 'mkdir "C:\My Test\<>"'

                    http://www.sqlservercentral.com/Forums/Topic604168-8-1.aspx[^]


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    S Offline
                    S Offline
                    Samarjeet Singh india
                    wrote on last edited by
                    #11

                    Thank you very much it working for me

                    1 Reply Last reply
                    0
                    • M Minghao Xue

                      below procedure should be the solution create procedure sp_create_directory ( @full_path varchar(500) ) as set nocount on declare @command varchar(1000) set @command = 'mkdir ' + @full_path exec master..xp_cmdshell @command , no_output set nocount off GO

                      S Offline
                      S Offline
                      Samarjeet Singh india
                      wrote on last edited by
                      #12

                      Thanks for your great help

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups