<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/PT-BR/fileExists?action=history&amp;feed=atom</id>
	<title>PT-BR/fileExists - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/PT-BR/fileExists?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PT-BR/fileExists&amp;action=history"/>
	<updated>2026-04-12T21:07:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PT-BR/fileExists&amp;diff=78699&amp;oldid=prev</id>
		<title>Lettify: Created page with &quot;__NOTOC__ {{BR/Funcao compartilhada}} Esta função verifica se um determinado arquivo existe em um resource.  ==Sintaxe== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; bool fileExists ( string filePath ) &lt;/syntaxhighlight&gt; {{PT-BR/POO|Esta é uma função estática abaixo da classe File.|File.exists}}  ===Argumentos necessários=== *'''filePath:''' O caminho do arquivo a ser criado seguindo o seguinte formato: '''&quot;:resourceName/path&quot;'''. '''resourceName''' é o nome do...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PT-BR/fileExists&amp;diff=78699&amp;oldid=prev"/>
		<updated>2023-12-20T17:59:47Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {{BR/Funcao compartilhada}} Esta função verifica se um determinado arquivo existe em um resource.  ==Sintaxe== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; bool fileExists ( string filePath ) &amp;lt;/syntaxhighlight&amp;gt; {{PT-BR/POO|Esta é uma função estática abaixo da classe File.|&lt;a href=&quot;/index.php?title=File&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;File (page does not exist)&quot;&gt;File&lt;/a&gt;.exists}}  ===Argumentos necessários=== *&amp;#039;&amp;#039;&amp;#039;filePath:&amp;#039;&amp;#039;&amp;#039; O &lt;a href=&quot;/wiki/Filepath&quot; title=&quot;Filepath&quot;&gt;caminho&lt;/a&gt; do arquivo a ser criado seguindo o seguinte formato: &amp;#039;&amp;#039;&amp;#039;&amp;quot;:resourceName/path&amp;quot;&amp;#039;&amp;#039;&amp;#039;. &amp;#039;&amp;#039;&amp;#039;resourceName&amp;#039;&amp;#039;&amp;#039; é o nome do...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{BR/Funcao compartilhada}}&lt;br /&gt;
Esta função verifica se um determinado arquivo existe em um resource.&lt;br /&gt;
&lt;br /&gt;
==Sintaxe==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool fileExists ( string filePath )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{PT-BR/POO|Esta é uma função estática abaixo da classe File.|[[File]].exists}}&lt;br /&gt;
&lt;br /&gt;
===Argumentos necessários===&lt;br /&gt;
*'''filePath:''' O [[filepath|caminho]] do arquivo a ser criado seguindo o seguinte formato: '''&amp;quot;:resourceName/path&amp;quot;'''. '''resourceName''' é o nome do resource do arquivo que vai estar lá, e '''path''' é o caminho do arquivo relativo ao diretório do resource.&lt;br /&gt;
:Por exemplo, se você quiser verificar se um arquivo chamado ''myfile.txt'' existe em um resource chamado ''mapcreator'', poderá ser feito através de um outro resource da seguinte forma: &amp;lt;code&amp;gt;fileExists(&amp;quot;:mapcreator/myfile.txt&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
:Se o arquivo, que quiser verificar a existência, estiver no resource atual, apenas o caminho do arquivo é necessário, ex.: &amp;lt;code&amp;gt;fileExists(&amp;quot;myfile.txt&amp;quot;)&amp;lt;/code&amp;gt;. Note que você deve usar as ''barras'' &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; para as pastas, se utilizar ''barra inversa'' &amp;lt;code&amp;gt;\&amp;lt;/code&amp;gt; a função vai retornar '''false'''.&lt;br /&gt;
&lt;br /&gt;
===Retorna===&lt;br /&gt;
Retorna '''true''' se o arquivo existir, '''false''' caso contrário.&lt;br /&gt;
&lt;br /&gt;
==Exemplo==&lt;br /&gt;
Este exemplo verifica se um arquivo existe no diretório de um resource.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function checkExistingFile(player,cmd,filename,resourcename)&lt;br /&gt;
	if not filename then -- se o jogador não especificar um nome/caminho de arquivo&lt;br /&gt;
		outputChatBox(&amp;quot;ERROR: Syntax '/checkfile filename resourcename(optional)'.&amp;quot;,player) -- exibe um erro&lt;br /&gt;
		return false  -- para a função aqui&lt;br /&gt;
	end&lt;br /&gt;
	if not resourcename then -- se o jogador não especificar o resource que quer verificar, então vamos usar o resource atual&lt;br /&gt;
		resourcename = getResourceName(resource) --todo resource tem uma variável global pré-definida chamada 'resource' que contém o objeto-resource daquele resource que o código estiver rodando, em outras palavras, a mesma coisa que utilizar getThisResource().&lt;br /&gt;
	else&lt;br /&gt;
		if not getResourceFromName(resourcename) then -- se um resource com o nome especificado não existir, será exibido o erro ao jogador e a função para&lt;br /&gt;
			outputChatBox(&amp;quot;ERROR: Resource &amp;quot;..resourcename..&amp;quot; doesn't exist.&amp;quot;,player) -- exibe a mensagem de erro&lt;br /&gt;
			return false -- para a função aqui&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- se a função não tiver parado em algum lugar acima, então teremos o resource e o caminho do arquivo corretos&lt;br /&gt;
	local exists = fileExists((&amp;quot;:%s/%s&amp;quot;):format(resourcename,filename)) -- usando uma forma mais curta de string.format, veja StringLibraryTutorial de Lua para saber mais&lt;br /&gt;
	if exists then&lt;br /&gt;
		outputChatBox((&amp;quot;The file %q in resource %q exists&amp;quot;):format(filename,resourcename))&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox((&amp;quot;The file %q in resource %q doesn't exist&amp;quot;):format(filename,resourcename))&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;exists&amp;quot;,checkExistingFile)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Veja também==&lt;br /&gt;
{{PT-BR/File functions}}&lt;/div&gt;</summary>
		<author><name>Lettify</name></author>
	</entry>
</feed>