アダム、
これがあなたのシナリオと一致するかどうかはわかりませんが、数年前に同様の問題がありました。ファイル サーバーでは、毎日新しいディレクトリが作成され、そのフォルダーにはその日のファイルが含まれていました。 問題は、時間が一貫していないことでした。 フォルダ(ディレクトリ)名の時刻は、その日の最初のファイルが到着した日時です。 そのため、具体的な時期は不明でした。
最も単純なJSLコマンドは使用することでしたフォルダー = ディレクトリ内のファイル (「パス」)再帰を使用しないでください。 次に、JSL を使用して、今日の日付で始まる、または今日の日付を含むフォルダーを検索します。それは完全に機能しましたが、サーバーには「無数の」フォルダーがあり、パフォーマンスはかなり遅かった.私は Windows オペレーティング システムを使用しているので、カスタム dir コマンドを実行するために cmd.exe で Run Program を使用しました。 たとえば、この MS Dir コマンド
dir /a:d /o:-dc:\temp\jsl*
フォルダー名がjslで始まるc:\tempディレクトリに存在する、最新のものから最も古いもの(/o:-dの順序は逆の日付)までリストされたすべてのフォルダー(/a:dすべてのディレクトリ)を返します。 したがって、現在の日付を使用してリストを絞り込むことができます。
私の「無数の」フォルダーの問題では、検索しなければならなかったディレクトリ名構造は 20180524*something_somethingelse のようでした。バックアップによってフォルダーのビルドが再開されることがあったため、リストに 2 つ、まれに 3 つの値が表示されることがありました。 しかし、逆順なので、リストの最初の項目がターゲット フォルダーでした。
私のスクリプトでは、ターゲット フォルダーを取得したら、Files In Directory () を使用します。これで、特定の不明なさまざまな時刻のディレクトリが得られ、各ファイルを処理してレポートを作成します。すべてリモートで (バッチで) )。
Mac を使用している場合は、Jim のすばらしい提案しか提供できません。 各ファイルについて、Files inDirectory() によって返されるリストで、今日の日付を含むファイルを検索し、複数ある場合は作成日を取得して最新のものを見つけます。
Windows を使用していて、パフォーマンスの問題に対処している場合は、JMP インストール ディレクトリ内のすべてのフォルダを取得する方法を示すスクリプトを次に示します。[この例のように単純なものについては、Files in 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 )
)
);