T thierry6031 Member Licensed User Longtime User Jan 12, 2019 #1 Hello I have a question about the file.exists method. Is it possible to use that method to check for an empty folder? For example : B4X: if file.exists (FolderName, "*.txt") then ' code if exists else ' code if no txt file found endif I tried it that way, but I always get false (meaning no file found) even if there are actually files. I want to prevent the user to overwrite existing file or to try to handle empty folders. Thanks Thierry
Hello I have a question about the file.exists method. Is it possible to use that method to check for an empty folder? For example : B4X: if file.exists (FolderName, "*.txt") then ' code if exists else ' code if no txt file found endif I tried it that way, but I always get false (meaning no file found) even if there are actually files. I want to prevent the user to overwrite existing file or to try to handle empty folders. Thanks Thierry
FrostCodes Active Member Licensed User Jan 12, 2019 #2 I dont think you can use wildcard for the filename.. Upvote 0
T thierry6031 Member Licensed User Longtime User Jan 12, 2019 #3 That's what I thought. But Has anybody a solution for this? I was thinking about using the file.listfiles method, and then checking for the list.size property to verify. But this supposes the folder to contain only the expected files or exactly nothing. Thanks Upvote 0
That's what I thought. But Has anybody a solution for this? I was thinking about using the file.listfiles method, and then checking for the list.size property to verify. But this supposes the folder to contain only the expected files or exactly nothing. Thanks
DonManfred Expert Licensed User Longtime User Jan 12, 2019 #4 thierry6031 said: But Has anybody a solution for this? Click to expand... the sinplest solution to check if a folder is empty is to get the list of files from this folder and check if it is "empty". B4X: dim flist as List = File.ListFiles(folder) Note that it also contains Files like "." or ".."... You probably also can use (or at least get some inspiration from) the WildcardFileListing class. Last edited: Jan 12, 2019 Upvote 0
thierry6031 said: But Has anybody a solution for this? Click to expand... the sinplest solution to check if a folder is empty is to get the list of files from this folder and check if it is "empty". B4X: dim flist as List = File.ListFiles(folder) Note that it also contains Files like "." or ".."... You probably also can use (or at least get some inspiration from) the WildcardFileListing class.