You are browsing the archive for file.

by chip

findUniqueFileName

April 24, 2008 in Linux, Mac OS X, Vista, Windows XP by chip

FUNCTION findUniqueFileName pPathAndFile
    set the itemdel to "."
    put item -1 of pPathAndFile into tExtension
    delete item -1 of pPathAndFile
    put empty into x
    REPEAT
        IF x is not empty THEN
            put pPathAndFile & "-" & x & "." & tExtension into tryThisFileName
        ELSE 
            put pPathAndFile & x & "." & tExtension into tryThisFileName
        END IF
        IF there is a file tryThisFileName THEN  -- find a unique filename
            add 1 to x
        ELSE
            return tryThisFileName
        END IF
    END REPEAT
END findUniqueFileName

by chip

fileNameFromPathAndFile

April 23, 2008 in Mac OS X, Vista, Windows XP by chip

FUNCTION fileNameFromPathAndFile tPathAndFile
    set the itemdel to "/"
    return the last item of tPathAndFile
END fileNameFromPathAndFile

by chip

theFileDetail

April 23, 2008 in Mac OS X by chip

FUNCTION theFileDetail tPathAndFile
    set the itemdel to "/"
    put item -1 of tPathAndFile into tFile
    delete item -1 of tPathAndFile
    put "/" after tPathAndFile
    set the defaultfolder to tPathAndFile
    put the detailed files into tFiles
    filter tFiles WITH urlencode(tFile) & comma & "*"
    return tFiles
END theFileDetail

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

by chip

stripExtension

April 23, 2008 in Linux, Mac OS X, Vista, Windows XP by chip

FUNCTION stripExtension p
    IF p contains "." THEN
        set the itemdel to "."
        delete item -1 of p
    END IF
    return p
END stripExtension