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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to create FileName or Folder name with space ?

How to create FileName or Folder name with space ?

Scheduled Pinned Locked Moved Database
helpcsharptutorialquestion
7 Posts 4 Posters 0 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.
  • G Offline
    G Offline
    Golden Jing
    wrote on last edited by
    #1

    Dear all, I have issue when i creat folder/condition with other foldername with space. In code bellow is i create foldername that with space Declare @ComMkDir varchar(100) (eg. C:\ComName\Test Folder Set @ComMkDir = 'mkDir ' + @ComComp EXEC master.dbo.xp_cmdshell @ComMkDir After create is just create "Test" folder. Thanks for your help...

    VB.Net

    A M 2 Replies Last reply
    0
    • G Golden Jing

      Dear all, I have issue when i creat folder/condition with other foldername with space. In code bellow is i create foldername that with space Declare @ComMkDir varchar(100) (eg. C:\ComName\Test Folder Set @ComMkDir = 'mkDir ' + @ComComp EXEC master.dbo.xp_cmdshell @ComMkDir After create is just create "Test" folder. Thanks for your help...

      VB.Net

      A Offline
      A Offline
      Andy_L_J
      wrote on last edited by
      #2

      This gets the result you want, change to suit:

      DECLARE @ComMkDir varchar(100)
      DECLARE @mkDir varchar(50) = 'C:\ComName\Test'
      DECLARE @ComComp varchar(50) = 'Folder'

      SET @ComMkDir = @mkDir + ' ' + @ComComp

      Print @ComMkDir

      RESULT:

      C:\ComName\Test Folder

      I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

      modified on Friday, December 25, 2009 9:46 PM

      G 1 Reply Last reply
      0
      • A Andy_L_J

        This gets the result you want, change to suit:

        DECLARE @ComMkDir varchar(100)
        DECLARE @mkDir varchar(50) = 'C:\ComName\Test'
        DECLARE @ComComp varchar(50) = 'Folder'

        SET @ComMkDir = @mkDir + ' ' + @ComComp

        Print @ComMkDir

        RESULT:

        C:\ComName\Test Folder

        I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

        modified on Friday, December 25, 2009 9:46 PM

        G Offline
        G Offline
        Golden Jing
        wrote on last edited by
        #3

        ohh maybe you don't undestand what i posted. I want to create folder not just print. you can test it. It is not acept with space.

        VB.Net

        T 1 Reply Last reply
        0
        • G Golden Jing

          ohh maybe you don't undestand what i posted. I want to create folder not just print. you can test it. It is not acept with space.

          VB.Net

          T Offline
          T Offline
          Tim Carmichael
          wrote on last edited by
          #4

          Put double quotes around the directory and file name. Eg: "c:\Temp Folder\Temporary File.txt" Tim

          G M 2 Replies Last reply
          0
          • G Golden Jing

            Dear all, I have issue when i creat folder/condition with other foldername with space. In code bellow is i create foldername that with space Declare @ComMkDir varchar(100) (eg. C:\ComName\Test Folder Set @ComMkDir = 'mkDir ' + @ComComp EXEC master.dbo.xp_cmdshell @ComMkDir After create is just create "Test" folder. Thanks for your help...

            VB.Net

            M Offline
            M Offline
            Md Marufuzzaman
            wrote on last edited by
            #5

            Try the following hope that may helped you...

            --EXEC spCreateF0lder 'C:\ComName\Test\' ,'Test Folder 1'
            CREATE PROCEDURE spCreateF0lder
            @DefaultPath varchar(MAX)
            ,@FolderName VARCHAR(100)
            AS
            BEGIN

            DECLARE @SqlScript VARCHAR (MAX)

            SET @SqlScript = 'EXEC master.dbo.xp_cmdshell ''' + ' mkDir ' + @DefaultPath + @FolderName + ''''

            EXEC @SqlScript
            Print @SqlScript

            END
            GO

            Thanks Md. Marufuzzaman


            Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

            modified on Saturday, December 26, 2009 8:35 AM

            1 Reply Last reply
            0
            • T Tim Carmichael

              Put double quotes around the directory and file name. Eg: "c:\Temp Folder\Temporary File.txt" Tim

              G Offline
              G Offline
              Golden Jing
              wrote on last edited by
              #6

              Thanks you so much it work well...

              VB.Net

              1 Reply Last reply
              0
              • T Tim Carmichael

                Put double quotes around the directory and file name. Eg: "c:\Temp Folder\Temporary File.txt" Tim

                M Offline
                M Offline
                Md Marufuzzaman
                wrote on last edited by
                #7

                I'm facing the following error: Output SqlScript: EXEC master.dbo.xp_cmdshell 'mkDir "C:\ComName\Test\Test Folder 1"' -- It works fine But when I try like EXEC @SqlScript ,it raise the following error. Msg 203, Level 16, State 2, Procedure spCreateF0lder, Line 19 The name 'EXEC master.dbo.xp_cmdshell 'mkDir "C:\ComName\Test\Test Folder 1"'' is not a valid identifier.

                Thanks Md. Marufuzzaman


                Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

                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