SQL Server Performance

From MS-SQL Query (without using xp_CmdShell) how can we check existence of a file on Server under specified Path?

Discussion in 'SQL Server 2005 General DBA Questions' started by bsethi24, Aug 26, 2010.

  1. bsethi24 New Member

    Dear All,
    Hi! I need a MS-SQL QUERY based solution (without using xp_CmdShell) to check that given file name (for ex.: - 123.jpg) is exists on connected Server under specified path or not.
    For example: -
    I am connected with a Web application Database server in Management studio. This server has 4 drives (C, D, E, F). In F drive there is a folder by the name "TEST".
    Now I need a QUERY (without using xp_CmdShell) by which I can check that "123.jpg" file is exists in this "TEST" folder or not.
    If possible, kindly solve this issue.
  2. satya Moderator

    Powershell is your answer if XP_CMDSHELL is not desired. You can use:
    # PowerShell Checks If a File Exists
    $WantFile = "C:Windowsexplorer.exe"
    $FileExists = Test-Path $WantFile
    If ($FileExists -eq $True) {Write-Host "Yippee"}
    Else {Write-Host "No file at this location"}

    You can see http://blogs.msdn.com/b/billramo/archive/2009/05/13/powershell-script-examples-from-dat314.aspx, http://www.simple-talk.com/sql/data...y-this-sql-server-dba-is-learning-powershell/ & http://sqlblog.com/blogs/allen_whit...using-powershell-and-sql-server-together.aspx on Powershell

Share This Page