我正在尝试创建一个可以增加文件名的函数.如果字符串的最后一个字符是数字,则递增它.如果最后一个字母是一个字母,那么添加_1或_2或_3(也增加它).我必须确保文件名是唯一的但我不能在文件名中使用datetime,因为所有文件名必须是<32个字符而没有扩展名.
EX: Apple_99.txt =>Apple_100
Ex: Apple_173 => Apple_174
EX: This_is_my_first_text.txt => This_is_my_first_text_1.txt
Ex: This_is_my_first_text_9.txt => This_is_my_first_text_10.txt
Run Code Online (Sandbox Code Playgroud)
我需要使用它来重命名文件,然后将其上传到ftp服务器.我发现了一个可以执行此类操作的函数,但只有在文件名只包含大写时才有效.如何修改此函数以便访问大写字母的小写字母?
这是功能:
function IncStr(Str: String; Amount: Integer; Index: Integer = -1): String;
const
MIN_VAL = 65; // 'A'
MAX_VAL = 90; // 'Z'
var
Digit, ToAdd, ToCarry: Integer;
begin
if (Index = 0) and (Amount > 0) then
begin
Result := Char(MIN_VAL + Amount - 1) + Str;
Exit;
end;
if Index = -1 then Index := Length(Str);
ToCarry := 0;
Digit := Ord(Str[Index]); …Run Code Online (Sandbox Code Playgroud) 是否有函数可以从给定路径获取最后创建的文件夹?我想查看最后创建的文件夹,以检查我的相机今天是否拍摄了照片。我想到的另一种方法是获取系统日期,然后开始搜索包含当前日期的文件夹。但是,如果相机日期错误,那么这种方法将不起作用!谢谢。还有其他想法吗?
前任:
if lastcreatedfolder(dir_path):='05012016' then
showmessage('TODAY A FOLDER WAS CREATED')
else
showmessage('NO FOLDER WAS CREATED TODAY!');
Run Code Online (Sandbox Code Playgroud)