FileKit
Description
FileKit is a Xojo module for robustly handling FolderItem
copying, deletion and moving.
I created it because the native FolderItem
Copy()
, Move()
and Remove()
methods are buggy.
This is particularly true on Windows (especially Windows 10).
This module uses the cp
and mv
shell commands on Unix systems (macOS and Linux) and the move
and
xcopy
commands on Windows.
Properties
Name | Type | Read-Only |
---|---|---|
ProtectedFolderItems | Dictionary |
✔ |
SafeMode | Boolean |
Methods
Name | Parameters | Returns |
---|---|---|
CopyTo | source As FolderItem , destination As FolderItem , overwrite As Boolean |
FileKit.Errors |
CopyTo | source As FolderItem , destination As FolderItem , overwrite As Boolean |
FileKit.Errors |
MoveTo | source As FolderItem , destination As FolderItem , overwrite As Boolean |
FileKit.Errors |
MoveTo | source As FolderItem , destination As FolderItem , overwrite As Boolean |
FileKit.Errors |
ReallyDelete | what As FolderItem , safeMode As Boolean |
Boolean |
ReallyDelete | what As FolderItem , safeMode As Boolean |
Boolean |
SetupProtectedFiles | Dictionary |
|
ToString | e As FileKit.Errors |
String |
UnixCopyFile | file As FolderItem , destination As FolderItem |
FileKit.Errors |
UnixCopyFolder | folder As FolderItem , destination As FolderItem |
FileKit.Errors |
UnixMoveFile | file As FolderItem , destination As FolderItem |
FileKit.Errors |
UnixMoveFolder | folder As FolderItem , destination As FolderItem |
FileKit.Errors |
WindowsCopyFile | file As FolderItem , destination As FolderItem |
FileKit.Errors |
WindowsCopyFolder | folder As FolderItem , destination As FolderItem |
FileKit.Errors |
WindowsMoveFile | file As FolderItem , destination As FolderItem |
FileKit.Errors |
WindowsMoveFolder | folder As FolderItem , destination As FolderItem |
FileKit.Errors |
Constants
Name | Type |
---|---|
QUOTE | String |
QUOTE As String The double quote character.
Enumerations
Errors
The various errors that can occur during file manipulation.
Name |
---|
Aborted |
AttemptToDeleteProtectedFolderItem |
CpError |
DestinationDoesNotExist |
DestinationIsNil |
MoveError |
None |
SourceDoesNotExist |
SourceIsNil |
UnableToCreateDestinationFolder |
UnableToDeleteFile |
UnableToDeleteFolder |
Unknown |
XcopyDiskWriteError |
Property Descriptions
ProtectedFolderItems As Dictionary
A dictionary containing paths that are protected. Key = Native path, Value = Boolean.
SafeMode As Boolean
True if FileKit should run in safe mode which prevents certain paths from being deleted.
Method Descriptions
CopyTo(source As FolderItem, destination As FolderItem, overwrite As Boolean) As FileKit.Errors
Copies source
to destination
.
source
is the file or folder to copy.
destination
must be a folder and must exist.
CopyTo(source As FolderItem, destination As FolderItem, overwrite As Boolean) As FileKit.Errors
Copies source
to destination
.
source
is the file or folder to copy.
destination
must be a folder and must exist.
MoveTo(source As FolderItem, destination As FolderItem, overwrite As Boolean) As FileKit.Errors
Mmoves source
to destination
.
source
is the file or folder to move.
destination
must be a folder.
MoveTo(source As FolderItem, destination As FolderItem, overwrite As Boolean) As FileKit.Errors
Mmoves source
to destination
.
source
is the file or folder to move.
destination
must be a folder.
ReallyDelete(what As FolderItem, safeMode As Boolean) As Boolean
Completely deletes what
even if it is a folder with contents. Returns True if successful.
ReallyDelete(what As FolderItem, safeMode As Boolean) As Boolean
Completely deletes what
even if it is a folder with contents. Returns True if successful.
SetupProtectedFiles() As Dictionary
Returns the Dictionary that stores the FolderItems that must never be deleted by ReallyDelete()
Which locations are protected depends upon the platform that the app is currently running on.
The following locations are protected on:
Windows:
ApplicationData
, Applications
, Desktop
, Documents
, Extensions
, Favourites
, Fonts
,
Movies
, Music
, Pictures
, Printers
, SharedApplicationData
, SharedDocuments
, System
,
UserHome
, Windows
macOS:
ApplicationData
, Applications
, Bin
, Desktop
, Documents
, Etc
, Favourites
, Fonts
, Home
,
Library
, Mount
, Movies
, Music
, Pictures
, Preferences
, Printers
, SBin
,
SharedApplicationData
, SharedDocuments
, SharedPreferences
, System
, UserBin
, UserHome
,
UserLibrary
, UsersBin
Linux:
ApplicationData
, Bin
, Desktop
, Documents
, Etc
, Home
, Library
, Mount
, Movies
,
Music
, Pictures
, SBin
, UserBin
, UserHome
, UserLibrary
, UsersBin
ToString(e As FileKit.Errors) As String
Returns a string representation of error e
.
UnixCopyFile(file As FolderItem, destination As FolderItem) As FileKit.Errors
Copies source
to destination
using the shell and the cp
command.
source
is the file to copy.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
does NOT contain an identically
named file as source
.
macOS and Linux only.
UnixCopyFolder(folder As FolderItem, destination As FolderItem) As FileKit.Errors
Copies source
to destination
using the shell and the cp
command.
source
is the folder to copy.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
is a folder and
destination
does NOT contain an identically named folder as source
.
macOS and Linux only.
UnixMoveFile(file As FolderItem, destination As FolderItem) As FileKit.Errors
Moves source
file to destination
using the shell and the mv
command.
source
is the file to move.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
does NOT contain an identically
named file as source
.
macOS and Linux only.
UnixMoveFolder(folder As FolderItem, destination As FolderItem) As FileKit.Errors
Moves source
folder to destination
using the shell and the mv
command.
source
is the folder to move.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
is a folder and
destination
does NOT contain an identically named folder as source
.
macOS and Linux only.
WindowsCopyFile(file As FolderItem, destination As FolderItem) As FileKit.Errors
Copies source
to destination
using the shell and the xcopy
command.
source
is the file to copy.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
does NOT contain an identically
named file as source
.
Windows-only.
WindowsCopyFolder(folder As FolderItem, destination As FolderItem) As FileKit.Errors
Copies source
to destination
using the shell and the xcopy
command.
source
is the folder to copy.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
is a folder and
destination
does NOT contain an identically named folder as source
.
Windows-only.
WindowsMoveFile(file As FolderItem, destination As FolderItem) As FileKit.Errors
Moves source
to destination
using the shell and the move
command.
source
is the file to move.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
does NOT contain an identically
named file as source
.
Windows-only.
WindowsMoveFolder(folder As FolderItem, destination As FolderItem) As FileKit.Errors
Moves source
to destination
using the shell and the move
command.
source
is the folder to move.
destination
specifies the folder that will become the parent of source
.
The method assumes that checks have already been made for the following conditions:
source
<> Nil and source
exists
destination
<> Nil and destination
exists and destination
is a folder and
destination
does NOT contain an identically named folder as source
.
Windows-only.