Problem with revCopyFile

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
RobertTeeter
Posts: 16
Joined: Tue May 25, 2021 3:56 pm

Problem with revCopyFile

Post by RobertTeeter » Mon Feb 03, 2025 7:50 pm

I am trying to replace a Mac app with a higher version. I have successfully used
revCopyFile in this script elsewhere. But, here, it doesn't.t work. The if statement is true.

Yes, I know there is version checking built in but I didn't do it that way. Distribution of app/exe is limited to immediate family only. Grandson is on Windows. I am Mac OS 15.2, LC 10.0.

The Script

if tAppExeVersionUpdateCheck > tAppExeVersionMusicRGTCheck then
put tFolderMusicRGT & slash & tTextToCheck & " -- 1" & return into msg -------
delete file tFolderMusicRGT & slash & tTextToCheck
put the result & " -- 2A" & return after msg ------
put the sysError & " -- 2B" & return after msg ------
put tFolderUpdate & slash & tTextUpdate into tFileToCopy
put tFileToCopy & " -- 3" & return after msg -------
put tFolderMusicRGT & " -- 4" & return after msg ------
revCopyFile tFileToCopy, tFolderMusicRGT
if the result is empty then ------
put "the result is empty -- 5A" & return after msg ---
else -----
put the result & " -- 5B" & return after msg -------
end if -----
if the sysError is empty then ------
put "the sysError is empty -- 6A" & return after msg ---
else -----
put the sysError & " -- 6B" & return after msg -------
end if
set the thumbPosition of scrollbar "Progress" to 100
put "Replacing Mac App with " & quote & tTextUpdate & quote & " is Completed." & \
return & return after field "Status"
else
put "Mac App - " & quote & tTextUpdate & quote & " is the latest !" & return & \
return after field "Status"
end if

The Message Box

/Users/RgtClassic/Desktop/Music-RGT/Music_Files -- 1
can't delete that file -- 2A
66 -- 2B
/Users/RgtClassic/Desktop/Music-RGT-Update-Test-1/Music-By-RGT-V73.app -- 3
/Users/RgtClassic/Desktop/Music-RGT -- 4
execution error -- 5B
66 -- 6B

Klaus
Posts: 14061
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem with revCopyFile

Post by Klaus » Mon Feb 03, 2025 8:14 pm

Hi Robert,

please use the CODE tags above (5th button from the left) after pasting your script.
That will keep the formatting and makes the script better readable_

Code: Select all

...
   if tAppExeVersionUpdateCheck > tAppExeVersionMusicRGTCheck then
      put tFolderMusicRGT & slash & tTextToCheck & " -- 1" & return into msg -------
      delete file tFolderMusicRGT & slash & tTextToCheck
      put the result & " -- 2A" & return after msg ------
      put the sysError & " -- 2B" & return after msg ------
      put tFolderUpdate & slash & tTextUpdate into tFileToCopy
      put tFileToCopy & " -- 3" & return after msg -------
      put tFolderMusicRGT & " -- 4" & return after msg ------
      revCopyFile tFileToCopy, tFolderMusicRGT
      if the result is empty then ------
         put "the result is empty -- 5A" & return after msg ---
      else -----
         put the result & " -- 5B" & return after msg -------
      end if -----
      if the sysError is empty then ------
         put "the sysError is empty -- 6A" & return after msg ---
      else -----
         put the sysError & " -- 6B" & return after msg -------
      end if
      set the thumbPosition of scrollbar "Progress" to 100
      put "Replacing Mac App with " & quote & tTextUpdate & quote & " is Completed." & \
            return & return after field "Status"
   else
      put "Mac App - " & quote & tTextUpdate & quote & " is the latest !" & return & \
            return after field "Status"
   end if   
...
One possible issue might be this line:

Code: Select all

delete file tFolderMusicRGT & slash & tTextToCheck
ALWAYS use parens whzen concatenating file and objenames, try this:

Code: Select all

delete file (tFolderMusicRGT & slash & tTextToCheck)
Hint: You may want to save some typing by using
"/" instead of SLASH
and
CR instead of RETURN :-)

Best

Klaus

RobertTeeter
Posts: 16
Joined: Tue May 25, 2021 3:56 pm

Re: Problem with revCopyFile

Post by RobertTeeter » Mon Feb 03, 2025 8:20 pm

Tried that - same result

/Users/RgtClassic/Desktop/Music-RGT/Music-By-RGT-V7.app -- 1
can't delete that file -- 2A
66 -- 2B
/Users/RgtClassic/Desktop/Music-RGT-Update-Test-1/Music-By-RGT-V73.app -- 3
/Users/RgtClassic/Desktop/Music-RGT -- 4
execution error -- 5B
2 -- 6B

Klaus
Posts: 14061
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem with revCopyFile

Post by Klaus » Mon Feb 03, 2025 9:25 pm

I was just guessing...

But wait, is the FILE you want to delete your (renamed) app: "Music-By-RGT-V7.app -- 1"?
If yes, then this is the problem: APPs on a Mac are actually FOLDERS and LC can only delete EMPTY folders.***

Try using the rm shell command:

Code: Select all

...
## Use QUOTES in case your path contains spaces, which the shell does not like:
put "rm -R" && QUOTE & tFolderMusicRGT & "/" & tTextToCheck & " -- 1" & QUOTE into tShell
get shell(tShell)
if the result <> EMPTY then
  anser the result
end if
...
Tested and works. :-)

Best

Klaus

***However one can select APPS in LC with "answer FILE..." which is a bit irritating. 8)

RobertTeeter
Posts: 16
Joined: Tue May 25, 2021 3:56 pm

Re: Problem with revCopyFile

Post by RobertTeeter » Mon Feb 03, 2025 10:33 pm

Thank you. That correctly deleted the old app. Correcting the update folder reference fixed the copy of the new app.

My Windows laptop is currently being used by grandson, please confirm that the "delete file (file ref)" will work on a Windows executable.

Klaus
Posts: 14061
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem with revCopyFile

Post by Klaus » Tue Feb 04, 2025 10:14 am

Yes, on Windows "whatever.exe" is in fact a FILE for LC and "delete file whatever.exe" will work! :-)

Post Reply

Return to “Talking LiveCode”