Posts: 69
Threads: 42
Joined: Jun 2006
I was not able to create a function with this condition. I tried the following code:
if(FileExists("$user profile$\01\*.*"))
ReplaceToolbarButtonText 0 "Not empty" "File Explorer toolbar"
It works if I refer to some specific file, but it does not work if I use asterisks to refer to any kind of file, as I did in the above code.
Posts: 117
Threads: 5
Joined: Nov 2015
07-16-2018, 02:43 AM
(This post was last modified: 07-16-2018, 02:51 AM by Start_Learning.)
Try this function
if
IsFileExist("$user profile$\01\*.*")
ReplaceToolbarButtonText 0 "Not empty" "File Explorer toolbar"
Function
IsFileExist
function# str'file
lpstr s=dir(_s.expandpath(file))
if(s=0) ret 0
ret 1
Posts: 69
Threads: 42
Joined: Jun 2006
Let’s suppose that the folder I want to check is C:\
What should be the code for the function?
Posts: 117
Threads: 5
Joined: Nov 2015
Macro
Macro33
if IsFileExist("c:\*.*")
,;do something
Posts: 69
Threads: 42
Joined: Jun 2006
Have you tested your code?
Posts: 117
Threads: 5
Joined: Nov 2015
I've tested on my part. What about you, did you try it out? What did you notice?
Posts: 1,337
Threads: 61
Joined: Jul 2006
I see a couple issues with this function
#1. if folder contains subfolders and has files doesn't detect it.
#2.
dir is an obsolete
function
Maybe something like this would be better
Function
IsFolderEmpty
function# str'folderpath
;checks folder and its subfolders(if they exist) to see if it's empty or not
;
;REMARKS
;;folderpath- must end with a \ and be top level of folder to check(subfolders are automatically checked)
;;folderpath example- $documents$\test folder\ (test folder is the desired(TopLevel) folder to check)
;;Returns: 1 if folder is not empty, 0 if folder is empty or If folder doesn't exist
;EXAMPLES
;if IsFolderEmpty("$documents$\test folder\")
,;out "not empty"
;if !IsFolderEmpty("$documents$\test folder\")
,;out "empty"
;int ReturnValue=IsFolderEmpty("$documents$\test folder\")
;out ReturnValue
str folder.getpath(folderpath "\*")
Dir d
foreach(d folder FE_Dir 0|4|32)
,if d.dir("*.*" 0)
,,ret 1
ret 0
Macro MacroExample
if IsFolderEmpty("$documents$\test folder\")
,out "not empty"
this is not the only solution
Feel free to correct or improve on this function or offer different solutions
Posts: 117
Threads: 5
Joined: Nov 2015
Kevin you're right, "dir" is now obsolete. So now I update my "IsFileExist" function to this:
Function
IsFileExist
function# str'file
Dir d; str s
foreach(d _s.expandpath(file) FE_Dir 0|4|32)
,s = d.FileName
,if s.len
,,ret 1
ret 0
Macro IsFileExist Test
out
;Note: folders ("c:\x1" and "d:\z1" are just empty folders for testing only.
str files=
;c:\*
;c:\temp\*.csv
;c:\temp\*.htm
;c:\temp\*.txt
;c:\temp\*.docx
;c:\x1\*
;d:\*
;d:\download\*.apk
;d:\download\*.epub
;d:\download\*.mobi
;d:\download\*.pdf
;d:\download\*.txt
;d:\download\*.rar
;d:\z1\*
str file
foreach file files
,if IsFileExist(file)
,,out F"{file} exist."
,else
,,out F"{file} is NONE!"