如何在cobol中获取目录中的所有文件
How to get all files in directory in cobol
我正在使用 GnuCOBOL(使用 Windows),我需要用它编写一个编译器。
我想问的是 - 给定目录路径,我可以修改其中的文件吗
使用 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
大小的假设,您希望在粗心大意之前将代码稍微弄乱一下。
我正在使用 GnuCOBOL(使用 Windows),我需要用它编写一个编译器。
我想问的是 - 给定目录路径,我可以修改其中的文件吗 使用 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
大小的假设,您希望在粗心大意之前将代码稍微弄乱一下。