Moved lib/libLog.lua to lib/dtutils/log.lua. Rewrote most of it to make it more configurable and easier to use. Updated doc format to a fixed list of fields. Did away with the comment blocks and just relying on the libdoc comments. Update doc tools to use new formats. Moved dtutils/extensions.lua to dtutils/string.lua. Pulled dtutils/processor.lua back for now since there is no context for it. Removed unneeded functions and cleaned up others.
This commit is contained in:
@@ -1,49 +1,25 @@
|
||||
--[[
|
||||
|
||||
dtutils/file.lua - common darktable lua file functions
|
||||
|
||||
Copyright (C) 2016 Bill Ferguson <wpferguson@gmail.com>.
|
||||
Copyright (C) 2016 Tobias Jakobs
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
]]
|
||||
|
||||
local dtutils_file = {}
|
||||
dtutils_file.libdoc = {
|
||||
Sections = {"Name", "Synopsis", "Description", "License"},
|
||||
Name = [[dtutils.file - common darktable lua file functions]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"]],
|
||||
Description = [[dtutils.file provides common file manipulation functions used in
|
||||
constructing Darktable lua scripts]],
|
||||
License = [[This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.]],
|
||||
functions = {}
|
||||
}
|
||||
|
||||
local dt = require "darktable"
|
||||
|
||||
local log = require "lib/libLog"
|
||||
local log = require "lib/dtutils.log"
|
||||
|
||||
dtutils_file.libdoc = {
|
||||
Name = [[dtutils.file]],
|
||||
Synopsis = [[common darktable lua file functions]],
|
||||
Usage = [[local df = require "lib/dtutils.file"]],
|
||||
Description = [[[dtutils.file provides common file manipulation functions used in
|
||||
constructing Darktable lua scripts]],
|
||||
Return_Value = [[df - library - the file functions]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = log.libdoc.License,
|
||||
Copyright = [[Copyright (C) 2016 Bill Ferguson <wpferguson@gmail.com>.]],
|
||||
Copyright = [[Copyright (C) 2016 Bill Ferguson <wpferguson@gmail.com>.
|
||||
Copyright (C) 2016 Tobias Jakobs]],
|
||||
functions = {}
|
||||
}
|
||||
|
||||
local gettext = dt.gettext
|
||||
|
||||
@@ -56,35 +32,22 @@ local function _(msgid)
|
||||
return gettext.dgettext("dtutils.file", msgid)
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
check_if_bin_exists - check if an executable is in the path
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.check_if_bin_exists(bin)
|
||||
bin - string - the binary to check for
|
||||
|
||||
DESCRIPTION
|
||||
check_if_bin_exists checks to see if the specified binary executable is
|
||||
in the path.
|
||||
|
||||
RETURN VALUE
|
||||
result - boolean - true if the executable was found, false if not
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[check_if_bin_exists - check if an executable is in the path]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["check_if_bin_exists"] = {
|
||||
Name = [[check_if_bin_exists]],
|
||||
Synopsis = [[check if an executable is in the path]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.check_if_bin_exists(bin)
|
||||
bin - string - the binary to check for]],
|
||||
Description = [[check_if_bin_exists checks to see if the specified binary executable is
|
||||
in the path.]],
|
||||
Return_Value = [[result - boolean - true if the executable was found, false if not]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.check_if_bin_exists(bin)
|
||||
@@ -95,71 +58,48 @@ function dtutils_file.check_if_bin_exists(bin)
|
||||
return result
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
split_filepath - split a filepath into parts
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.split_filepath(filepath)
|
||||
filepath - string - path and filename
|
||||
|
||||
DESCRIPTION
|
||||
split_filepath splits a filepath into the path, filename, basename and filetype and puts
|
||||
that in a table
|
||||
|
||||
RETURN VALUE
|
||||
result - table - a table containing the path, filename, basename, and filetype
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[split_filepath - split a filepath into parts]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["split_filepath"] = {
|
||||
Name = [[split_filepath]],
|
||||
Synopsis = [[split a filepath into parts]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.split_filepath(filepath)
|
||||
filepath - string - path and filename]],
|
||||
Description = [[split_filepath splits a filepath into the path, filename, basename and filetype and puts
|
||||
that in a table]],
|
||||
Return_Value = [[result - table - a table containing the path, filename, basename, and filetype]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.split_filepath(str)
|
||||
-- strip out single quotes from quoted pathnames
|
||||
str = string.gsub(str, "'", "")
|
||||
local result = {}
|
||||
-- Thank you Tobias Jakobs for the awesome regular expression, which I tweaked a little
|
||||
result["path"], result["filename"], result["basename"], result["filetype"] = string.match(str, "(.-)(([^\\/]-)%.?([^%.\\/]*))$")
|
||||
return result
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
get_path - get the path from a file path
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_path(filepath)
|
||||
filepath - string - path and filename
|
||||
|
||||
DESCRIPTION
|
||||
get_path strips the filename and filetype from a path and returns the path
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the path
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[get_path - get the path from a file path]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["get_path"] = {
|
||||
Name = [[get_path]],
|
||||
Synopsis = [[get the path from a file path]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_path(filepath)
|
||||
filepath - string - path and filename]],
|
||||
Description = [[get_path strips the filename and filetype from a path and returns the path]],
|
||||
Return_Value = [[result - string - the path]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.get_path(str)
|
||||
@@ -167,33 +107,21 @@ function dtutils_file.get_path(str)
|
||||
return parts["path"]
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
get_filename - get the filename and extension from a file path
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_filename(filepath)
|
||||
filepath - string - path and filename
|
||||
|
||||
DESCRIPTION
|
||||
get_filename strips the path from a filepath and returns the filename
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the file name and type
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[get_filename - get the filename and extension from a file path]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["get_filename"] = {
|
||||
Name = [[get_filename]],
|
||||
Synopsis = [[get the filename and extension from a file path]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_filename(filepath)
|
||||
filepath - string - path and filename]],
|
||||
Description = [[get_filename strips the path from a filepath and returns the filename]],
|
||||
Return_Value = [[result - string - the file name and type]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.get_filename(str)
|
||||
@@ -201,33 +129,22 @@ function dtutils_file.get_filename(str)
|
||||
return parts["filename"]
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
get_basename - get the filename without the path or extension
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_basename(filepath)
|
||||
filepath - string - path and filename
|
||||
|
||||
DESCRIPTION
|
||||
get_basename returns the name of the file without the path or filetype
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the basename of the file
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[get_basename - get the filename without the path or extension]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["get_basename"] = {
|
||||
Name = [[get_basename]],
|
||||
Synopsis = [[get the filename without the path or extension]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_basename(filepath)
|
||||
filepath - string - path and filename]],
|
||||
Description = [[get_basename returns the name of the file without the path or filetype]],
|
||||
Description = [[get_basename returns the name of the file without the path or filetype
|
||||
]],
|
||||
Return_Value = [[result - string - the basename of the file]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.get_basename(str)
|
||||
@@ -235,33 +152,21 @@ function dtutils_file.get_basename(str)
|
||||
return parts["basename"]
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
get_filetype - get the filetype from a filename
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_filetype(filepath)
|
||||
filepath - string - path and filename
|
||||
|
||||
DESCRIPTION
|
||||
get_filetype returns the filetype from the supplied filepath
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the filetype
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[get_filetype - get the filetype from a filename]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["get_filetype"] = {
|
||||
Name = [[get_filetype]],
|
||||
Synopsis = [[get the filetype from a filename]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.get_filetype(filepath)
|
||||
filepath - string - path and filename]],
|
||||
Description = [[get_filetype returns the filetype from the supplied filepath]],
|
||||
Return_Value = [[result - string - the filetype]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.get_filetype(str)
|
||||
@@ -269,34 +174,23 @@ function dtutils_file.get_filetype(str)
|
||||
return parts["filetype"]
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
check_if_file_exists - check if a file or path exist
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.check_if_file_exists(filepath)
|
||||
filepath - string - a file or path to check
|
||||
|
||||
DESCRIPTION
|
||||
check_if_file_exists checks to see if a file or path exists
|
||||
|
||||
RETURN VALUE
|
||||
result - boolean - true if the file or path exists, false if it doesn't
|
||||
|
||||
]]
|
||||
|
||||
-- Thanks Tobias Jakobs for the idea
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[check_if_file_exists - check if a file or path exist]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["check_if_file_exists"] = {
|
||||
Name = [[check_if_file_exists]],
|
||||
Synopsis = [[check if a file or path exist]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.check_if_file_exists(filepath)
|
||||
filepath - string - a file or path to check]],
|
||||
Description = [[check_if_file_exists checks to see if a file or path exists]],
|
||||
Return_Value = [[result - boolean - true if the file or path exists, false if it doesn't]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.check_if_file_exists(filepath)
|
||||
@@ -307,33 +201,21 @@ function dtutils_file.check_if_file_exists(filepath)
|
||||
return result
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
chop_filetype - remove a filetype from a filename
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.chop_filetype(path)
|
||||
path - string - a filename with or without a path
|
||||
|
||||
DESCRIPTION
|
||||
chop_filetype removes the filetype from the filename
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the path and filename without the filetype
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[chop_filetype - remove a filetype from a filename]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["chop_filetype"] = {
|
||||
Name = [[chop_filetype]],
|
||||
Synopsis = [[remove a filetype from a filename]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.chop_filetype(path)
|
||||
path - string - a filename with or without a path]],
|
||||
Description = [[chop_filetype removes the filetype from the filename]],
|
||||
Return_Value = [[result - string - the path and filename without the filetype]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.chop_filetype(path)
|
||||
@@ -341,30 +223,10 @@ function dtutils_file.chop_filetype(path)
|
||||
return string.sub(path, 1, -length)
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
file_copy - copy a file to another name/location
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.file_copy(fromFile, toFile)
|
||||
fromFile - string - name of file to copy from
|
||||
toFile - string - name of file to copy to
|
||||
|
||||
DESCRIPTION
|
||||
copy a file using a succession of methods from operating system
|
||||
to a pure lua solution
|
||||
|
||||
RETURN VALUE
|
||||
result - boolean - nil on error, true on success
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[file_copy - copy a file to another name/location]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["file_copy"] = {
|
||||
Name = [[file_copy]],
|
||||
Synopsis = [[copy a file to another name/location]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.file_copy(fromFile, toFile)
|
||||
fromFile - string - name of file to copy from
|
||||
@@ -372,6 +234,12 @@ dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Description = [[copy a file using a succession of methods from operating system
|
||||
to a pure lua solution]],
|
||||
Return_Value = [[result - boolean - nil on error, true on success]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.file_copy(fromFile, toFile)
|
||||
@@ -404,30 +272,10 @@ function dtutils_file.file_copy(fromFile, toFile)
|
||||
return result
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
file_move - move a file from one directory to another
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.file_move(fromFile, toFile)
|
||||
fromFile - string - name of the original file
|
||||
toFile - string - the new file location and name
|
||||
|
||||
DESCRIPTION
|
||||
Move a file from one place to another. Try a succession of methods from
|
||||
builtin to operating system to a pure lua solution.
|
||||
|
||||
RETURN VALUE
|
||||
result - boolean - nil on error, some value on success
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[file_move - move a file from one directory to another]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["file_move"] = {
|
||||
Name = [[file_move]],
|
||||
Synopsis = [[move a file from one directory to another]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.file_move(fromFile, toFile)
|
||||
fromFile - string - name of the original file
|
||||
@@ -435,6 +283,12 @@ dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Description = [[Move a file from one place to another. Try a succession of methods from
|
||||
builtin to operating system to a pure lua solution.]],
|
||||
Return_Value = [[result - boolean - nil on error, some value on success]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.file_move(fromFile, toFile)
|
||||
@@ -458,31 +312,10 @@ function dtutils_file.file_move(fromFile, toFile)
|
||||
return success -- nil on error, some value if success
|
||||
end
|
||||
|
||||
--[[
|
||||
NAME
|
||||
filename_increment - add a two digit increment to a filename
|
||||
|
||||
SYNOPSIS
|
||||
local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.filename_increment(filepath)
|
||||
filepath - string - filename to increment
|
||||
|
||||
DESCRIPTION
|
||||
filename_increment solves the problem of filename confllict by adding an
|
||||
increment to the filename. If the supplied filename has no increment then
|
||||
"01" is added to the basename. If the filename already has an increment, then
|
||||
1 is added to it and the filename returned.
|
||||
|
||||
RETURN VALUE
|
||||
result - string - the incremented filename
|
||||
|
||||
]]
|
||||
|
||||
dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
Sections = {"Name", "Synopsis", "Description", "Return_Value"},
|
||||
Name = [[filename_increment - add a two digit increment to a filename]],
|
||||
Synopsis = [[local df = require "lib/dtutils.file"
|
||||
dtutils_file.libdoc.functions["filename_increment"] = {
|
||||
Name = [[filename_increment]],
|
||||
Synopsis = [[add a two digit increment to a filename]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.filename_increment(filepath)
|
||||
filepath - string - filename to increment]],
|
||||
@@ -491,6 +324,12 @@ dtutils_file.libdoc.functions[#dtutils_file.libdoc.functions + 1] = {
|
||||
"01" is added to the basename. If the filename already has an increment, then
|
||||
1 is added to it and the filename returned.]],
|
||||
Return_Value = [[result - string - the incremented filename]],
|
||||
Limitations = [[]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.filename_increment(filepath)
|
||||
@@ -520,4 +359,36 @@ function dtutils_file.filename_increment(filepath)
|
||||
return incremented_filepath
|
||||
end
|
||||
|
||||
|
||||
dtutils_file.libdoc.functions["create_unique_filename"] = {
|
||||
Name = [[create_unique_filename]],
|
||||
Synopsis = [[create a unique filename from the supplied argment]],
|
||||
Usage = [[local df = require "lib/dtutils.file"
|
||||
|
||||
local result = df.create_unique_filename(filepath)
|
||||
filepath - string - the path and filename requested]],
|
||||
Description = [[create_unique_filename takes a requested filepath and checks to see if
|
||||
it exists. If if doesn't then it's returned intact. If it already exists, then a two
|
||||
digit increment is added to the filename and it is tested again. The increment keeps
|
||||
increasing until either a unique filename is found or there have been 100 attempts.]],
|
||||
Return_Value = [[result - string - the incremented filename]],
|
||||
Limitations = [[create_unique_filename will only attempt 100 increments.]],
|
||||
Example = [[]],
|
||||
See_Also = [[]],
|
||||
Reference = [[]],
|
||||
License = [[]],
|
||||
Copyright = [[]],
|
||||
}
|
||||
|
||||
function dtutils_file.create_unique_filename(filepath)
|
||||
while dtutils_file.check_if_file_exists(filepath) do
|
||||
filepath = dtutils_file.filename_increment(filepath)
|
||||
-- limit to 99 more exports of the original export
|
||||
if string.match(dtfileutils.get_basename(filepath), "_(d-)$") == "99" then
|
||||
break
|
||||
end
|
||||
end
|
||||
return filepath
|
||||
end
|
||||
|
||||
return dtutils_file
|
||||
|
||||
Reference in New Issue
Block a user