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 work with folder and File ?

How to work with folder and File ?

Scheduled Pinned Locked Moved Database
csharpdatabasesql-serversysadmin
8 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 use SQL Server 2005. I want to creat Folder If have that folder name ready I want to rename it or delete old folder. About File is the same. Have any command for do it ? Thanks for help....

    VB.Net

    A N M 3 Replies Last reply
    0
    • G Golden Jing

      Dear All, I use SQL Server 2005. I want to creat Folder If have that folder name ready I want to rename it or delete old folder. About File is the same. Have any command for do it ? Thanks for help....

      VB.Net

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

      You need to use xp_cmdshell, but you will probably have permissioning problems! Why do file activities from sql server?

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      1 Reply Last reply
      0
      • G Golden Jing

        Dear All, I use SQL Server 2005. I want to creat Folder If have that folder name ready I want to rename it or delete old folder. About File is the same. Have any command for do it ? Thanks for help....

        VB.Net

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        I believe this can be done via

        xp_cmdshell

        In the below example I am creating a directory initially and next time if such a directory is found, I will rename that

        declare
        @cmdpath nvarchar(60)
        , @Location nvarchar(100)
        , @message nvarchar(max)
        set @Location = N'C:\NewFolder'
        set @cmdpath = 'MD '+ @Location

        create table #result(result nvarchar(255))
        insert into #result (result) exec master.dbo.xp_cmdshell @cmdpath
        select @message = ISNULL(@message + ' - ','') + result from #result where result is not null
        if(@message is not null)
        begin
        EXEC xp_cmdshell 'RENAME C:\NewFolder RenamedFolder'
        end
        select @message
        drop table #result

        For more info you can visit a) Using xp_cmdshell[^] b) xp_cmdshell[^] :)

        Niladri Biswas

        1 Reply Last reply
        0
        • G Golden Jing

          Dear All, I use SQL Server 2005. I want to creat Folder If have that folder name ready I want to rename it or delete old folder. About File is the same. Have any command for do it ? Thanks for help....

          VB.Net

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Why are you using SQL Server to interact with the file system, this is generally not recommended as it exposes the file system to database users. Most server environments will not allow that.

          Never underestimate the power of human stupidity RAH

          G 1 Reply Last reply
          0
          • M Mycroft Holmes

            Why are you using SQL Server to interact with the file system, this is generally not recommended as it exposes the file system to database users. Most server environments will not allow that.

            Never underestimate the power of human stupidity RAH

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

            thanks. the reason is that the data in backup to txt file so some have to rename, delete or create new. about Folder when delete it ask are you sure (Y/N)? how can type Y ?

            VB.Net

            M 1 Reply Last reply
            0
            • G Golden Jing

              thanks. the reason is that the data in backup to txt file so some have to rename, delete or create new. about Folder when delete it ask are you sure (Y/N)? how can type Y ?

              VB.Net

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Your statement does not make a lot of sense to me. You back up your database to a text file? Are you nuts? Ok what database are you using that does not have a backup facility to properly backup and restore your data. As someone suggested you can use xpcommand shell but it sounds like a nightmare to me. Permissioning will be another issue as well. I would recommend you TOTALLY rethink you data management.

              Never underestimate the power of human stupidity RAH

              G N 2 Replies Last reply
              0
              • M Mycroft Holmes

                Your statement does not make a lot of sense to me. You back up your database to a text file? Are you nuts? Ok what database are you using that does not have a backup facility to properly backup and restore your data. As someone suggested you can use xpcommand shell but it sounds like a nightmare to me. Permissioning will be another issue as well. I would recommend you TOTALLY rethink you data management.

                Never underestimate the power of human stupidity RAH

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

                thanks you so much.

                VB.Net

                1 Reply Last reply
                0
                • M Mycroft Holmes

                  Your statement does not make a lot of sense to me. You back up your database to a text file? Are you nuts? Ok what database are you using that does not have a backup facility to properly backup and restore your data. As someone suggested you can use xpcommand shell but it sounds like a nightmare to me. Permissioning will be another issue as well. I would recommend you TOTALLY rethink you data management.

                  Never underestimate the power of human stupidity RAH

                  N Offline
                  N Offline
                  Niladri_Biswas
                  wrote on last edited by
                  #8

                  To be honest, though I proposed a solution, but I agree with you. If the person is using .net, it is better to go ahead with SMO. In any other technology, there must be some option to go ahead.

                  Niladri Biswas

                  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