Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Query whether a file exists.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Jul 03, 2021 12:14 pm    Post subject: Query whether a file exists. Reply with quote

Test if all file types exist in the path you know.
(For windows below codes are working)

Note: The current test code is an alternative to "LuaFileSystem" (lfs.).

Code:
function pathExist(pth,fl1)
local file=pth..fl1
  local fl2  = os.rename(file, file)
  if not fl2 then
  print("File not found")
  else
  print("file available")
 end
 return fl2
end


Use:
Code:
--Folder
pathExist([[C:\Users\YourUserName\OneDrive\]],"Pictures")


Code:
--files
pathExist([[C:\Users\YourUserName\Desktop\]],"Sample.txt")


-------------------------------- or check and reName:
Code:
function pathExist(pth,fl1,refl)
local file=pth.."\\"..fl1
  local fl2  = os.rename(file, file)
  if not fl2 then
  print("File not found")
  else
  if refl=="" then
  print("file available")
  else
  local file1=pth.."\\"..refl
  local fl2  = os.rename(file, file1)
  print("New File name: "..refl.." success!")
  end
 end
 return fl2
end


--Use check name:
Code:
local cedir=getCheatEngineDir()
--or [[C:\Program Files\Cheat Engine 7.2]]

pathExist(cedir,"lua53-32.dll","")


--Use rename:
Code:
pathExist([[C:\Users\YourUserName\Desktop]],"lost1.txt","lost2.txt")


Enjoy it!
Back to top
View user's profile Send private message
maskelihileci
Cheater
Reputation: 0

Joined: 08 Oct 2016
Posts: 43

PostPosted: Thu Feb 24, 2022 7:03 pm    Post subject: Reply with quote

Can we get the file version?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri Feb 25, 2022 2:05 am    Post subject: Reply with quote

maskelihileci wrote:
Can we get the file version?


Code:
function pathExist(fl1,refl)

local fl2  = os.rename(fl1, fl1)
local fl3  = os.rename(refl, refl)

  if not fl2 then  return print(fl1 .. " not found")
  elseif not fl3 then  return print(refl .. " not found")
  else
  vrs1=fl1:match("[^\\]*$")
  vrs2=refl:match("[^\\]*$")
   if tonumber(vrs1:match("(%d+%p*%d+)")) < tonumber(vrs2:match("(%d+%p*%d+)")) then

    print("File: '"..vrs2.."' Newer!")
    return vrs2
    else
    print("File: '"..vrs1.."' Newer!")
    return vrs1
   end
  end
end

 local pth=[[C:\Users\YourUserName\Desktop]] --edit YourUserName
rst1=pathExist(pth .. "\\CT_V14.122.txt",pth .. "\\CT_V14.132.txt")
print(rst1)


-->rst1
--File: 'CT_V14.132.txt' Newer!

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites