rename&revcopyfile
Jan Decroos
jan.decroos at groepvanroey.be
Fri Apr 12 10:28:03 EDT 2002
use-revolution at lists.runrev.com writes:
>there is a tiny bug in the "revlibrary.rev", script of button "revCommon"
>
>....
>on revCopyFile pSrcFile, pDestFile
> if the platform is "MacOS" then
> if "applescript" is in the alternateLanguages then
> do revAppleScriptFull(copyFile,pSrcFile,pDestFile) as applescript
> else return "Error: AppleScript not installed"
> else if the platform is "Win32" then
> revSetWindowsShellCommand
> set the itemDel to "/"
> #### put item -1 of pSrcFile into tFileName
> #### not necessary, see below
>
> set the itemDel to comma
> #### get shell ("copy" &&
>revWindowsFromUnixPath(quote&pSrcFile"e) &&
>revWindowsFromUnixPath(quote&pDestFile&"\"&tFileName"e))
> #### wont work, does not even give an error
> #### 1 concenating too much... ;-)
> ####pDestFile contains the complete path to the destination-file
>including the filename.
>
> get shell ("copy" && revWindowsFromUnixPath(quote&pSrcFile"e) &&
>revWindowsFromUnixPath(quote&pDestFile"e))
>#### this works
>
> else
> get shell ("cp -f" && quote&pSrcFile"e && quote&pDestFile"e)
> end if
> return the result
>end revCopyFile
The original reCopyFile was made in assumption the second argument is a FOLDER,
despite the name (pDestFile).
I've changed some scripts and tested it for MacOS 9.2 (classic)
the script replace the scripts in the revCommon stack in revLibrary.
What's changed and what should still be done ?
1. revCopyFile
- 2nd argument can now be a volume, folder of file name
- AppleScript part changed so the file can be copied to the
- another folder (copy file)
- another disk (copy file)
- the same folder with another file name (duplicate file)
- it the pDestination (file) already exists, it will be deleted (should it?)
just like in the UNIX part (cp -f ... )
- windows part : used pDestination which contains the fullpath name of the new
file
2. revApplescriptFull :
- case "duplicateFile" added
- getASDestKind added to check destination's kind (folder or disk) (earlier
could not copy to "/powerBook HD" for instance)
3. TO DO :
- revPathtoApplescript : should take care of aliasses?? (if an alias is in the
path, should it be resolved ?)
- the test if the "Desktop Folder" is in pPath should be changed if running
under macOS 9.2 Classic (under Mac OS X)
(AppleScript's pathname should not stop at "desktop Folder" (only under
'pure' OS 9), but should place it in the real path structure under OSX. Maybe
this is solved when previous "todo" is done because desktop folder is an alias
Here my scripts. Please comment...
on revCopyFile pSrcFile, pDestination
set the itemDel to "/"
put last item of pSrcFile into lSrcFName
-- "/powerBook HD" is not a folder, "/Powerbook HD/" is a folder
if the number of items of pDestination = 2 and last char of pDestination <>
"/" then put "/" after pDestination
if there is a folder pDestination then
if last char of pDestination <> "/" then put "/" after pDestination
put lSrcFName after pDestination
end if
if pDestination = pSrcFile then return "Execution error : source file and
destination file are identical !"
put (item 1 to -2 of pSrcFile)&"/" into lSrcFldr
put (item 1 to -2 of pDestination)&"/" into lDestFldr
put last item of pDestination into lDesFName
if there is not a folder lDestFldr then
return "Execution error : invalid destination folder !"
end if
-- make it consistent to UNIX "cp -f ..."
if there is a file pDestination then delete file pDestination
if the platform is "MacOS" then
if "applescript" is in the alternateLanguages then
if lSrcFldr = lDestFldr then
do revAppleScriptFull(duplicateFile,pSrcFile,lDestFldr) as applescript
if "error" is not in the result then
do "tell application" && quote & "Finder" & quote & cr & tab & "set
the name of" && the result && "to" && quote & lDesFName & quote && cr & "end
tell" as applescript
end if
else
do revAppleScriptFull(copyFile,pSrcFile,lDestFldr) as applescript
if "execution error" is not in the result then
if lSrcFName <> lDesFName then
rename file (lDestFldr & lSrcFName) to pDestination
end if
end if
end if
else return "Error: AppleScript not installed"
else if the platform is "Win32" then
revSetWindowsShellCommand
get shell ("copy" && revWindowsFromUnixPath(quote&pSrcFile"e) &&
revWindowsFromUnixPath(quote&pDestination"e))
else
get shell ("cp -f" && quote&pSrcFile"e && quote&pDestination"e)
end if
return the result
end revCopyFile
function getASDestKind pPath
set the itemDel to "/"
if the number of items of pPath = 2 then get "disk"
else get "folder"
return it
end getASDestKind
function revApplescriptFull pfunction,pSrc,pDest
switch pfunction
case "deleteFolder"
put "tell application" && quote & "Finder" & quote & cr & tab & "delete
folder" && revPathtoApplescript(pSrc) && cr & "end tell" into tApplescriptfull
exit switch
case "copyFolder"
put getASDestKind(pDest) into lKind
put "tell application" && quote & "Finder" & quote & cr & tab & "copy
folder" && revPathtoApplescript(pSrc) && "to "&lKind &&
revPathtoApplescript(pDest) && cr & "end tell" into tApplescriptfull
exit switch
case "copyFile"
put getASDestKind(pDest) into lKind
put "tell application" && quote & "Finder" & quote & cr & tab & "copy file"
&& revPathtoApplescript(pSrc) && "to "&lKind && revPathtoApplescript(pDest) &&
cr & "end tell" into tApplescriptfull
exit switch
case "duplicateFile"
put "tell application" && quote & "Finder" & quote & cr & tab & "duplicate
file" && revPathtoApplescript(pSrc) && cr & "end tell" into tApplescriptfull
exit switch
case "moveFolder"
put getASDestKind(pDest) into lKind
put "tell application" && quote & "Finder" & quote & cr & tab & "move
folder" && revPathtoApplescript(pSrc) && "to "&lKind &&
revPathtoApplescript(pDest) && cr & "end tell" into tApplescriptfull
exit switch
end switch
return tApplescriptfull
end revApplescriptFull
Jan
More information about the use-livecode
mailing list