Create a new folder in TSQL

  • Hi i'd like to create a new folder in TSQL the folder name should look like WK##

    where ## is the week number.

    The week number will change each week. I'd like this to be part of a stored procedure..

  • Hi

    You will have to extended procedures for this. Check out these extended procedures on the net

    xp_create_subdir ,xp_dirtree.

    "Keep Trying"

  • sql_Reporter (11/18/2008)


    Hi i'd like to create a new folder in TSQL the folder name should look like WK##

    where ## is the week number.

    The week number will change each week. I'd like this to be part of a stored procedure..

    use xp_cmdshell command you can create folders. for more info. see SQL BOL.

  • Here is my try at this, the code runs ok but it does not create a folder for me ?

    Any ideas

    declare @md varchar(100), @Path varchar(100),@wk_novarchar(2)

    set@wk_no = datepart(wk,getdate())

    --print @wk_no

    SET@Path = 'E:\temp\'

    SET@md ='mkdir' + @Path +'WK' + @wk_no

    EXECxp_cmdshell@md, no_output

    PRINT@md

  • sql_Reporter (11/18/2008)


    Here is my try at this, the code runs ok but it does not create a folder for me ?

    Any ideas

    declare @md varchar(100), @Path varchar(100),@wk_novarchar(2)

    set@wk_no = datepart(wk,getdate())

    --print @wk_no

    SET@Path = 'E:\temp\'

    SET@md =' mkdir ' + @Path +'WK' + @wk_no

    EXECxp_cmdshell@md, no_output

    PRINT@md

    Your script is correct just put spaces on the left and right of the 'mkdir' (see bolded part above). The command you generated if you print it is mkdirE:\temp\MK47 the command shell doesn't recognize the mkdir command.

    "-=Still Learning=-"

    Lester Policarpio

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply