You are browsing the archive for delete.

by chip

trashLocalFolderIfExists

April 23, 2008 in Mac OS X by chip

Apparently there is no way to do this on Windows- even from the shell!

But here’s the OS X version:


FUNCTION trashLocalFolderIfExists tPathAndFile
    IF there is a folder tPathAndFile THEN
        set the itemdel to "/"
        put the last item of tPathAndFile into tFolderName
        rename folder tPathAndFile to specialfolderpath("trsh") & "/" & tFolderName --! need Win32 switch
        IF the result is not empty THEN
            return "Got an error while trying to delete" && tPathAndFile & ":" && the result
        END IF
    ELSE
        return "HEELP! Went to delete a folder that wasn't there:" && tPathAndFile
    END IF
END trashLocalFolderIfExists

by chip

trashLocalFileIfExists

April 23, 2008 in Mac OS X by chip

Apparently impossible on Windows.


FUNCTION
trashLocalFileIfExists tPathAndFile

    IF there is a file tPathAndFile THEN
        set the itemdel to "/"
        put fileNameFromPathAndFile(tPathAndFile) into tFileName
        put pathFromPathAndFile(tPathAndFile) into tPath
        IF item 2 of tPath is "Volumes" THEN
            put "/Volumes/" & item 3 of tPath & "/.Trashes/" into tTrashPath
            rename file tPathAndFile to tTrashPath & tFileName & the time
        ELSE
            rename file tPathAndFile to specialfolderpath("trsh") & tClipName & the time
        END IF
        IF the result is not empty THEN
            return "Got an error while trying to delete" && tPathAndFile & ":" && the result
        END IF
    ELSE
        return "HEELP! Went to delete a file that wasn't there:" && tPathAndFile
    END IF
END trashLocalFileIfExists