我不熟悉progress 4GL,我写了以下代码来将文件从输入目录移动到输出目录。但令人担忧的是,我想在移动之前/之后重命名文件。
define variable m_inp as character no-undo initial "C:\Input\Test.csv".
define variable m_outpath as character no-undo initial "C:\Output".
file-info:filename = m_inp.
if file-info:file-size > 0
then
unix silent value("mv -f " + m_inp + ' ' + m_outpath).
else
unix silent value("rm -f " + m_inp).发布于 2020-10-16 03:30:41
请记住,如果源和目标位于不同的文件系统上,"mv“将转换为复制操作,然后是删除操作。对于大文件来说,这可能会很慢。
下面应该执行您想要的两步过程:
define variable m_inp as character no-undo initial "abc123.txt".
define variable m_outpath as character no-undo initial "/tmp/abc123.txt".
define variable newName as character no-undo initial "/tmp/123abc.txt".
file-info:filename = m_inp.
/*** using "UNIX" command (ties your code to UNIX :( ***/
/***
if file-info:file-size <= 0 then
unix silent value( "rm -f " + m_inp ).
else
do:
unix silent value( "mv -f " + m_inp + ' ' + m_outpath ).
unix silent value( "mv -f " + m_outpath + ' ' + newName ).
end.
***/
/*** OS portable functions ***/
if file-info:file-size <= 0 then
os-delete value( m_inp ).
else
do:
os-rename value( m_inp ) value( m_outpath ).
os-rename value( m_outpath ) value( newName ).
end.实际上,没有理由在两个不同的命令中执行“移动”和“重命名”,除非您要测试“移动”在两者之间是否成功。如果你这样做,那么我假设你一定已经有了那段代码。
如果文件名和路径是单独输入的,那么您可能还希望使用SUBSTITUTE()函数来构建完整的路径字符串。如下所示:
define variable dir1 as character no-undo initial ".".
define variable dir2 as character no-undo initial "/tmp".
define variable name1 as character no-undo initial "abc123.txt".
define variable name2 as character no-undo initial "123abc.txt".
define variable path1 as character no-undo.
define variable path2 as character no-undo.
/** prompt the user or whatever you really do to get the directory and file names
**/
path1 = substitute( "&1/&2", dir1, name1 ).
path2 = substitute( "&1/&2", dir2, name2 ).
file-info:filename = path1.
if file-info:file-size <= 0 then
os-delete value( path1 ).
else
os-rename value( path1 ) value( path2 ).https://stackoverflow.com/questions/64365823
复制相似问题