locked
Is it possible to check directoryname RRS feed

  • Question

  • Hi

    I  have no administrator right in sql , But I have the right  to the server to create the folder and remove the folder. Is there anyway can I check if the folder exist on the server when I pass the argument as foldername. Please can you advise me

    Regards

    Pol


    polachan

    Sunday, February 23, 2020 8:37 AM

Answers

  • Is it possible to check folder using ipaddress for example the folder 10.20.000\c:\contact

    That would be \\10.10.10.10\C$\Contact, but that would only work if SQL Server has permission to the administrative C$ on that computer, which it should not have, so the answer is in practice: no.

    But as I said, checking for folders from SQL Server is the wrong thing to do, so exaplain what you want to achieve and may be able to offer a solution.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by polachan Monday, February 24, 2020 10:26 AM
    Sunday, February 23, 2020 10:29 PM
  • Hi polachan,

    If using SQL Server to check, the account should have sufficient permissions to access the folder and files. Read-only should be enough.

    After obtaining the permission, 'NETWORK SERVICE' account will not have sufficient right into most folders. You may click on 'Properties' of the special folders, then click on the 'Security' tab and set 'Network Service'.

    Best Regards,

    Lily


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by polachan Monday, February 24, 2020 10:26 AM
    Monday, February 24, 2020 3:38 AM

All replies

  • You create manually a folder , am I right? Can you show the script you created a folder?

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Sunday, February 23, 2020 8:50 AM
    Answerer
  • Declare @ParentFolder VARCHAR(255),

    set @ParentFolder =  'C:\mssql\dumps\';
    EXEC master..xp_subdirs @ParentFolder
    IF @@ROWCOUNT > 0
     Print 'Path Exists'
    ELSE
     PRINT 'Path Does Not Exist'
    Sunday, February 23, 2020 10:46 AM
  • Yes I am creating the folder manually


    polachan

    Sunday, February 23, 2020 7:23 PM
  • It  is not working 

    when I apply the command

    Declare @ParentFolder VARCHAR(255)
    set @ParentFolder =  'C:\contact\';
    EXEC master..xp_subdirs @ParentFolder
    IF @@ROWCOUNT > 0
     Print 'Path Exists'
    ELSE
     PRINT 'Path Does Not Exist'

    xp_subdirs could not access 'C:\contact\*.*': FindFirstFile() returned error 3, 'The system cannot find the path specified.' the folder still exist there


    polachan


    • Edited by polachan Sunday, February 23, 2020 7:25 PM
    Sunday, February 23, 2020 7:24 PM
  • Did you create the folder on the same machine as SQL Server is running on?

    Overall, this is something you normally do not use SQL Server for. What gave you the idea to use SQL Server to check for folders in the first place? That is, in the grand scheme of things, what do you want to achieve?


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Proposed as answer by Naomi N Sunday, February 23, 2020 10:06 PM
    Sunday, February 23, 2020 7:50 PM
  • Is it possible to check folder using ipaddress for example the folder 10.20.000\c:\contact

    polachan

    Sunday, February 23, 2020 10:04 PM
  • Is it possible to check folder using ipaddress for example the folder 10.20.000\c:\contact

    That would be \\10.10.10.10\C$\Contact, but that would only work if SQL Server has permission to the administrative C$ on that computer, which it should not have, so the answer is in practice: no.

    But as I said, checking for folders from SQL Server is the wrong thing to do, so exaplain what you want to achieve and may be able to offer a solution.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by polachan Monday, February 24, 2020 10:26 AM
    Sunday, February 23, 2020 10:29 PM
  • Hi polachan,

    If using SQL Server to check, the account should have sufficient permissions to access the folder and files. Read-only should be enough.

    After obtaining the permission, 'NETWORK SERVICE' account will not have sufficient right into most folders. You may click on 'Properties' of the special folders, then click on the 'Security' tab and set 'Network Service'.

    Best Regards,

    Lily


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by polachan Monday, February 24, 2020 10:26 AM
    Monday, February 24, 2020 3:38 AM