gpt4 book ai didi

arrays - PASCAL:循环遍历数组来创建文件夹?

转载 作者:行者123 更新时间:2023-12-02 09:53:46 24 4
gpt4 key购买 nike

因此,我正在创建一个 pascal 脚本,它将在主目录中创建一个目录,并在该新目录中创建多个文件夹。 (插入 XZibit 双关语)

现在,我们在工作中执行此操作的方式是将这些变量发送到一个 exe,然后该 exe 将根据传递的内容创建目录(在本例中为路径“fullpath”)。

我不确定我是否正确地处理了这个问题,并且会喜欢更杰出的 PASCAL 大师的意见:)

const
ARRAY1: Array[1..9] of String = (
'NQN', 'Documents', 'Correspondences',
'Worksheets', 'Reports', 'Claims',
'Certificate of Insurance', 'Invoice', 'Monthly Reports'
);
var
i: Integer;
fullpath, path, name, os, es, cmd: String;
Code : LongWord;
res: Integer;

Begin
path := 'Policies'
fullpath := path+'\'+[i]
for i := 1 to 9 do
IF(ReqList.Values['sRM_ID'] = '') then
Begin
cmd := 'C:\XXX\bin\mkdir.exe "'+fullpath+'"';
res :=ExecuteProc(cmd, 'C:\XXX\bin', true, -1, true, nil, os, es, code);
if(res = 0) then
Begin
ReqList.values['NoErrors'] := '1';
ReqList.Values['Response_content']:= '{"valid":"1","message":"'+ReplaceString(ReplaceString(os,#13,'',false),#10,'',false)+'"}';
end
else
begin
ReqList.Values['NoErrors'] := '0';
Reqlist.Values['Response_Content'] := '{"valid":"0","message":"'+ReplaceString(ReplaceString(os,#13,'',false),#10,'',false)+'"}';
end;
END
ELSE
Begin
ReqList.Values['Response_Content'] := '{"valid":"0","message":"A folder or file with the same name already exists."}';
End;
ReqList.Values['Response_ContentType'] := 'HTML';

最佳答案

一旦确定了数组中每个条目的绝对路径,如果它们尚不存在,ForceDirectories 就会创建它们,正如 bummi 上面建议的那样。

假设您的根路径是相对于当前可执行路径的,它可能像这样简单:

const
ARRAY1: Array [1 .. 9] of String = ('NQN', 'Documents', 'Correspondences',
'Worksheets', 'Reports', 'Claims', 'Certificate of Insurance', 'Invoice',
'Monthly Reports');
var
s: string;
path: string;
fullpath: string;
begin
path := 'Policies';
for s in ARRAY1 do
begin
fullpath := ExpandFileName(IncludeTrailingPathDelimiter(path) + s);
ForceDirectories(fullpath);
end;
end;

关于arrays - PASCAL:循环遍历数组来创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19361732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com