亚当,
我不确定这是否符合您的情况,但几年前我遇到过类似的问题。在文件服务器上,每天都会创建一个新目录,该文件夹包含当天的文件。 问题是时间不一致。 文件夹(目录)名称的时间为当天第一个文件到达的日期时间。 因此,具体时间不得而知。
最简单的 JSL 命令是使用folders = 目录中的文件(“路径”)并且不要使用递归。 然后使用 JSL 搜索以今天日期开头或包含今天日期的文件夹。这工作得很好,但是,服务器有“无数”的文件夹,而且性能非常慢。我使用的是 Windows 操作系统,所以我使用带有 cmd.exe 的运行程序来运行自定义目录命令。 例如,这个 MS Dir 命令
目录 /a:d /o:-dc:\temp\jsl*
将返回我的 c:\temp 目录中文件夹名称以 jsl 开头的所有文件夹(/a:d 所有目录),从最近到最旧(/o:-d 顺序反向日期)。 所以我可以使用当天的日期来缩小列表的范围。
对于我的“无数”文件夹问题,我必须搜索的目录名称结构类似于 20180524*something_somethingelse。因为有时备份会重新启动文件夹构建,所以有时我会在列表中得到 2 个值,很少有 3 个值。 但因为它是倒序的,所以我列表中的第一项是目标文件夹。
在我的脚本中,一旦我得到目标文件夹,我就会使用目录中的文件 (),现在我有了具有特定的、未知的、变化的时间的目录,并处理每个文件并创建一个报告,所有这些都是远程的(批量的) ).
如果您使用的是 Mac,我只能提供 Jim 的非常棒的建议。 对于每个文件,在 Files inDirectory() 返回的列表中搜索包含今天日期的文件,如果超过一个,则获取创建日期并找到最新的一个。
如果您使用的是 Windows,并且您正在处理性能问题,那么这里有一个脚本可以说明如何获取 JMP 安装目录中的所有文件夹。[注意像这个例子一样简单的东西,Directory() 中的文件是最好的解决方案。]
// Get the full path for the JMP Install Directory
jmpDir = Convert File Path( "$JMP_Home", Windows );
Show( jmpDir );
// Build the DOS "dir" command
// dir /-C /T:C /S "C:\Program Files\SAS\JMPPRO\13\Samples\Data\*.J*" > c:\temp\dirOut_rp.txt
// --- DOS requires quoted file paths if the path includes spaces Program Files has a space
//this has no output file and /b only the directory name is returned
cmd_txt ="\[/c dir /a:d /b /-c /o:-d "]\"
|| jmpDir //will replace it with the full path of your installed JMP directory
||"\[* ]\";
show(cmd_txt ); //see the log file
//results returned as text
rpobj = RunProgram(Executable("CMD.EXE" ),
Options({Eval(cmd_txt)}),
ReadFunction("text")
);
show(rpobj);
if(length(rpobj) >0, dirList= words(rpobj,"\!N") );
show(dirList);
/*
{"ExcelProfiler", "imagemaps", "Tip of the Day", "Help", "Resources", "pptx",
"Flash", "Documentation", "tkext", "Scoring", "Samples", "Web", "Maps"}
*/
//____________________________________________________________________________________________
//alternate command to return information to a file
outDir = "c:\temp\dirOut_rp.txt";
cmd_txt ="\[/c dir /a:d /b /-c /o:-d "]\"
|| jmpDir //will replace it with the full path of your installed Sample Data directory
|| "\[*" > ]\"
|| outDir;
show(cmd_txt ); //see the log file
t0 = Today();
rpobj = RunProgram(Executable("CMD.EXE" ),
Options({Eval(cmd_txt)}),
ReadFunction("text")
);
//--- ReadFunction is reading statements from the OS, it reads until the program quits.
// This command suspends subsequent JSL until executable has completed the tasks.
//==== Show results=============================================================================
// A couple of "checks" that you may employ here if the file does not does not exist or if it is older than expected
If( !File Exists( outDir ) | (Creation Date( outDir ) - t0 > 10),
Caption( "There was a problem with the dir command, it did not run. Aborting..." );
Wait( 4 );
Caption( Remove );
Throw();
);
// Open the results file as text stored in column 1
dir_dt = Open(
outDir,
columns( Name( "Dir results" ) = Character ),
Import Settings(
End Of Line( CRLF ),
End Of Field( CRLF ), // ensures only 1 column
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 1 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
Labels( 0 ),
Data Starts( 1 ),
Lines To Read( All ),
Year Rule( "10-90" )
)
);
您没有说明如何指定从哪个目录获取文件,所以我只使用了 Pick Directory()。我假设您只有一个标准文件夹可以访问,在这种情况下,您可以使用以下方法绕过 Pick Directory():
folder = "<YOUR folder="" path="">";</YOUR>
吉姆,
感谢您的帮助,
我不知道选择目录功能是否可以非提示运行?我的脚本应该每天在后台运行,没有用户参与
谢谢
这是一个简单的脚本,我认为它可以让您了解如何找出满足您需求的文件
Names Default To Here( 1 );
folder = Pick Directory();
// Get all of the files in the folder
FileList = Files In Directory( folder );
// Create the known part of the files to look for
Header = Char( Day( Today() ) ) || "_" || Char( Month( Today() ) ) || "_" ||
Char( Year( Today() ) - 2000 ) || "_";
// Loop through the found files and eliminate all that do not
// match the pattern we are looking for
For( i = N Items( FileList ), i >= 1, i--,
If( Left( FileList, Length( Header ) ) != Header,
FileList = Remove( FileList, i, 1 )
)
);