0
我正在使用GnuCOBOL(使用Windows),我需要編寫一個編譯器。如何獲取cobol中的目錄中的所有文件
我在問的是 - 給定的目錄路徑,我可以使用COBOL修改它裏面的文件 嗎?說你不知道文件名是很重要的。你只知道包含它們的目錄的路徑。
我正在使用GnuCOBOL(使用Windows),我需要編寫一個編譯器。如何獲取cobol中的目錄中的所有文件
我在問的是 - 給定的目錄路徑,我可以使用COBOL修改它裏面的文件 嗎?說你不知道文件名是很重要的。你只知道包含它們的目錄的路徑。
這裏是POSIX系統
identification division.
program-id. SAMPLE.
environment division.
configuration section.
repository.
function all intrinsic.
data data division.
working-storage section.
01 dir usage pointer.
01 dent usage pointer.
01 dirent based.
05 filler pic x(19). *> HERE BE DRAGONS
05 entname pic x(256).
05 filler pic x(237).
01 sayname pic x(256).
*> ************************************************
code procedure division.
call "opendir" using
by content z"."
returning dir
on exception
display "error: no opendir found" upon syserr end-display
bail stop run returning 1
end-call
if dir not equal null then
call "readdir" using
by value dir
returning dent
end-call
perform until dent equal null
*> set address of the based dirent and pull out the name
set address of dirent to dent
initialize sayname
string entname delimited by x"00" into sayname end-string
display trim(sayname TRAILING) end-display
call "readdir" using
by value dir
returning dent
end-call
end-perform
call "closedir" using by value dir end-call
else
call "perror" using by content z"" returning omitted end-call
bail stop run returning 1
end-if
done goback.
end program SAMPLE.
最初發佈於SourceForge上,採用GPL許可協議的一些代碼。由於對dirent
的大小進行了假設,您可能希望將代碼放在一點點之前,然後再放在不知情的位置。
我們有一個C $ LIST-DIRECTORY股票庫函數用於執行堆,但現在您需要查看opendir,POSIX的readdir和Windows上的FindFirstFile FindNextFile。或者你可以看看蛛網管,用'dir'或'ls'使用'pipe-open'並將字符串讀入工作存儲區。 Bing上的代碼爲'gnucobol cobweb pipes'。 –
你正在使用哪個操作系統?你的意思是「通過」還是「解析」? 「改變它們」是什麼意思?當它不起作用時會發生什麼?你試過什麼代碼? –