<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Checking Files and Folders - MSSQL Query</title>
	<atom:link href="https://mssqlquery.com/tag/sql-checking-files-and-folders/feed" rel="self" type="application/rss+xml" />
	<link>https://mssqlquery.com</link>
	<description>MSSQL and TSQL Programming and TSQL Examples</description>
	<lastBuildDate>Fri, 24 Mar 2023 05:21:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.1</generator>

<image>
	<url>https://mssqlquery.com/wp-content/uploads/2023/06/cropped-mssql-query-icon-32x32.png</url>
	<title>SQL Checking Files and Folders - MSSQL Query</title>
	<link>https://mssqlquery.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Checking Files and Folders in SQL Server</title>
		<link>https://mssqlquery.com/checking-files-and-folders-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Mon, 08 Nov 2021 19:32:51 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Checking Files and Folders in SQL Server]]></category>
		<category><![CDATA[Checking Files SQL Server]]></category>
		<category><![CDATA[SQL Checking Files and Folders]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=309</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about how to control files and folders in SQL Server. In some cases in SQL Server, you may want to have your file or folder checked for existence and take action accordingly. Before SQL Server 2017, we were&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/checking-files-and-folders-in-sql-server">Checking Files and Folders in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about how to control files and folders in SQL Server.</p>
<p>In some cases in SQL Server, you may want to have your file or folder checked for existence and take action accordingly.</p>
<p>Before SQL Server 2017, we were doing this using the <strong>xp_fileexist</strong> command.</p>
<pre class="line-numbers"><code class="language-sql">EXEC xp_fileexist 'C:/test.txt'</code></pre>
<p>I created a file called test.txt under the C drive. When you run the SQL query, you will see a result similar to the one below.</p>
<p><img decoding="async" fetchpriority="high" class="alignnone wp-image-311 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-1.jpg" alt="Checking Files and Folders in SQL Server" width="700" height="491" srcset="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-1-300x210.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>&nbsp;</p>
<p>The <strong>File Exists</strong> field is returned as 1 because there is a file named <strong>test.txt</strong> in the C directory.</p>
<pre class="line-numbers"><code class="language-sql">EXEC xp_fileexist 'C:/Program Files'</code></pre>
<p>When you run the above query, you will see the following result.</p>
<p><img decoding="async" class="alignnone wp-image-312 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-2.jpg" alt="Checking Files and Folders in SQL Server" width="700" height="478" srcset="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-2.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-2-300x205.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>Since we checked the folder, the <strong>File is a Directory</strong> field returned 1, and the <strong>Parent Directory Exists</strong> field informs us whether the folder is in the parent directory.</p>
<p>You will check the values in <strong>File Exists</strong> for file queries and<strong> File is a Directory</strong> for folder queries.</p>
<p>After SQL Server 2017, we do this using the <strong>sys.dm_os_file_exists</strong> command.</p>
<pre class="line-numbers"><code class="language-sql">SELECT * FROM sys.dm_os_file_exists('C:/test.txt');</code></pre>
<p>When you run the above query, you will see the following result.</p>
<p><img decoding="async" class="alignnone wp-image-313 size-full" src="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-3.jpg" alt="Checking Files and Folders in SQL Server" width="700" height="486" srcset="https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-3.jpg 700w, https://mssqlquery.com/wp-content/uploads/2021/11/checking-files-and-folders-in-sql-server-3-300x208.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>The query result worked the same as <strong>xp_fileexist</strong>.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 370</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/checking-files-and-folders-in-sql-server">Checking Files and Folders in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
