find a file, copy a file

If we pull all the BB courses content exchange archive log files together, we can have a lot of them.  For each course, there is a the log file and the _detailed.txt file formatted like

BatchCxCmd_archive_AR101A_12JA.txt 
and BatchCxCmd_archive_AR101A_12JA_detailed.txt

If we  have a list of courses for which we want to accumulate the above archive logs, we can do that with powershell. Get a list of the courses we want, and save it in a text file.  Now, if necessary, extract the archive logs into one or more directories.  We will have at least 2xs as many files as course, plus an invoke and a BatchCxCmd file.

Now – first step.  Read the file of courses into an array.

$courseArray = @()
gc e:\blackboard\apps\snapshot\bin\psscripts\60list.txt|foreach {
$courseArray += $_
}

Next – read the directory or directories of of the logs with getchild-item.  This output is a directory object, so we need to extract the “name” of the file.  Next – the name is not the same as the course, so we need to deal with that – use replace() on the name.

$files=gci E:\blackboard\logs\archives\errors\content-exchange
$files|foreach-object {
$fname = $_.name
$cname = $fname.replace("BatchCxCmd_archive_","").replace(".txt","").replace("_details","")
...
}

We have taken the file name and extracted what should be the course id in $cname. If this messed-up name matches one of the course-ids in the array, copy it to a suitable location.

Now we are concerned that a course might not have been archived, or that it is not in a particular folder.  If we get either the txt file or the details.txt file, we know we have a hit, and we could construct the path to both items.  But since after working on the name, either of the two files will match the course id; (replace(“details”,””) will either work on details, or not work and fail sliently on the shorter .txt file), so we can run the entire list and look for matches.

After we get a match, copy the file from $_.name to another location.

if ($courseArray -contains $cname)
{
copy-item `
E:\blackboard\logs\archives\errors\content-exchange\$ss `         e:\blackboard\apps\snapshot\bin\psscripts\moveit
}

Find the moveit folder with 2xs the number of txt files as courses, zip it up and send it off.

Charlie-Mike.

Other enhancements could be to directly access the archives logs in the zip archive folders, and to use data on the clipboard instead of reading in from a file.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.