2013-10-14 43 views
2

所以我創建了一個pascal腳本,它將在主目錄內創建一個目錄,並且在該新目錄內創建多個文件夾。 (插入XZibit雙關語)PASCAL:通過數組循環來創建文件夾?

現在我們做這個工作的方式,我們將這些變量發送到一個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'; 
+3

就以[ForceDirectories]看看(http://docs.embarcadero.com/products/ rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_ForceDirectories.html)並使用* real *(完整)fullpathes。 – bummi

+1

使用腳本語言編寫腳本任務更有意義 –

+0

exe使用它的預定目錄,然後將提供的路徑以這些文件夾的目標爲基礎。 我打算爲ForceDirectories保留該選項卡,因爲這看起來非常有用。 – Doodely

回答

4

一旦你確定了你的陣列中的每個條目的絕對路徑,ForceDirectories將創建它們如果它們不存在,就像上面提到的那樣。

假設你的根路徑是相對於當前的可執行文件路徑,也可能是這樣簡單: