in reply to Re^3: Check multiple file names exist in directory and create another trigger file after existing files processed
in thread Check multiple file names exist in directory and create another trigger file after existing files processed

vickycanada:

Sorry, but I can't seem to figure out what you're asking.

So I'll just throw something out and see if it helps... ;^)

# Fetch all .zip files in the incoming directory my @zipfiles = glob "$srcDir/*.zip"; # Scan through the files to find out which XXX bits may exist my %XXXlist; for my $file (@zipfiles) { if ($file =~ /(alphat|numerict|updatet).(.*).zip/) { # OK one of our desired prefixes match, second capture group is +a valid XXX value $XXXlist{$2}++; } } # Now we can go on and see what we can process for my $XXX (keys %XXXlist) { if (-E "$srcDir/alphat.$XXX.zip" and -E "$srcDir/numerict.$XXX.zip" and -E "$srcDir/updatet.$XXX.zip") { # all files are found, so go do some work } else { # Not all files are present yet. } }

Did that help? If not, please try to expand your question a bit so I can figure out what you mean.

Note: I normally try to test my code before posting it, but I definitely didn't even try this time, so you may have to fiddle with it a bit.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

  • Comment on Re^4: Check multiple file names exist in directory and create another trigger file after existing files processed
  • Download Code

Replies are listed 'Best First'.
Re^5: Check multiple file names exist in directory and create another trigger file after existing files processed
by vickycanada (Novice) on Nov 22, 2017 at 17:11 UTC

    Thank you, again. The issue is here reading each filename from the directory and do compare. If it matches process all three files and then create a new *.done file to process further. This script runs once a week so we do not worry about old files. because there will always be three files will dropped in the source folder where this script should look after at specific interval.

    I made some changes as advised but it is not throwing any error but eventually end up with Exit code 0.
    $inputFileName = $ARGV[0]; $inputFilewithPath = $ARGV[1]; $destinationFileName = ""; $destinationFilePath = "\\mftshare-dev\Test\customoutput\Test1"; $triggerFileName = ""; my @zipfiles = glob "\\mftshare-dev\cpa\customoutput\hubidp\*.zip"; for my $file (@zipfiles) { if ($inputFileName =~ /alphat_(.*)\.zip/) { my $key = $1; # whatever was between alphat_ and the .zip bits. if (-f "numerict_${key}.zip" && -f "updatet_${key}.zip") { $destinationFileName = sprintf("%s%s%s", $destinationFilePath, + $inputFileName); $triggerFileName = sprintf("%s%s%s", $destinationFilePath , "c +pa_trigger.done"); $returnVal = system("ftmscmd /tcp /send /file /node:VIP /DT:B +/CrLf:Y /ppa1:S,L,COMMAND,\"echo > $triggerFileName\" /TC:3 $inputFil +ewithPath $destinationFileName"); } else { printf "WARNING: EXPECTED FILES NOT FOUND. INVESTIGATION REQUI +RED"; exit 8; } } }

      vickycanada:

      Hint: Try printing the contents of $destinationFilePath, and you'll get a hint at the problem you're likely having:

      print "<$destinationFilePath>\n";

      Oh, yes, one thing I forgot to mention (it bit me before). Sometimes your files may not be *complete* when they appear, so you need to be sure to delay processing the files until you're certain that they're done. I've had processes that would generate files, but would take several minutes to complete. Normally, I'd simply track the size of the file as well as the time I last saw the size of the file change. Then I'd process the file only after a reasonable amount of time after the file stops changing in length.

      You generally only have to do this when the file is being generated in or copied to the target directory. To avoid those problems, I generally advise people to generate/copy them into a temporary or working directory, and then move them to the target directory once generation/copy is complete. (Generally a move/rename operation is atomic/effectively instantaneous, so you don't need to worry about processing an incomplete file.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      This *pl file is linked with another *.wsend template which look for the source folder. below is *wsend template details. Thank you!
      LocalDirectory: \\Mftshare-dev\cpa\customoutput\hubidp DNICommand: perl test.pl $(LocalFile) $(LocalFileName) SubDirectory: No SuccessAction: move SuccessFile: \\Mftshare-dev\cpa\archive\hubidp\$(LocalFile) +.$(YYYYMMDD).$(HHMMSS) FailureAction: move FailureFile: \\Mftshare-dev\cpa\failure\hubidp\$(LocalFile) +.$(YYYYMMDD).$(HHMMSS) NetworkErrorAction: move NetworkErrorFile: \\Mftshare-dev\cpa\failure\hubidp\$(LocalFile) +.$(YYYYMMDD).$(HHMMSS) ScanInterval: 10s AutoEnable: Yes LeaveFileName: .\leave\leavefile.CPAtoHUBIDP1 PostActionFail: Leave AuditDirectory: .\Audit\CPAtoHUBIDP1