' ' Command line script to organize the files created by the blackboard ' assignment download zip *after* it is unzipped into the desired ' *parent* directory. The assignment name is passed as a commandline ' parameter, or the main method can be called directly with it as ' parameter. The script moves assignmentName_user_filename to ' assignmentName/user/filename and converts assignmentName_username.txt ' to assignmentName/user/HW-comments.txt (replace slash with backslash ' in Windows). ' import os, os.path Public Function main(PROJECT_PREFIX As Object) PROJECT_PREFIX = PROJECT_PREFIX.strip().replace(" ", "_") Dim PROJECT_PREFIX_ As Integer PROJECT_PREFIX_ = PROJECT_PREFIX + "_" Dim file_list() As String file_list = Directory.GetFiles(Directory.GetCurrentDirectory()) ' current directory file list ' def filesToMove(name): ' locally defined function, which can read variables ' Return ' in the outer function file_list = [name for name= 0 To file_list.Length - 1 ' list comprehension for files if name.startswith(PROJECT_PREFIX_)] ' satisfying condition Dim prefixLen As Integer prefixLen = len(PROJECT_PREFIX_) ' include underscore if(not Directory.Exists(PROJECT_PREFIX)) Then ' if directory dones not exist mkdir(PROJECT_PREFIX) ' create the directory End If for filename= 0 To file_list.Length - 1 Dim i As Integer i = prefixLen while IsNumeric(Mid(file_list(filename), i + 1, 1)) And LCase(Mid(file_list(filename), i + 1, 1)) >="a" And LCase(Mid(file_list(filename), i + 1, 1)) <="z": ' move past alphanumeric user i += 1 End While Dim username As Integer username = Mid(file_list(filename), prefixLen + 1, i - prefixLen) Dim newFilename As Integer newFilename = Mid(file_list(filename), i+1 + 1, Len(file_list(filename)) - (i+1 )) ' +1: skip "_" or "."; rest is filename if newFilename = "txt" Then ' special file created if comments added newFilename = "HW-comments.txt" End If Dim newDir As Integer newDir = PROJECT_PREFIX + "/" + username ' join 2 path components if(not Directory.Exists(newDir)) Then ' if newDir does not exist mkdir(newDir) ' create the directory End If Dim newLocation As Integer newLocation= newDir + "/" + newFilename ' assemble path to file My.Computer.FileSystem.RenameFile(file_list(filename), newLocation) ' moves and renames the file Next End Function Public Sub Routine2 Dim __name__ As String if __name__ = "__main__" Then ' import sys if Environment.GetCommandLineArgs().Length <> 2 Then ' sys.argv lists command line parameters Dim Python2VBText As New TextBox Python2VBText.MultiLine = True Python2VBText.Width = 200 Python2VBText.Height = 100 Form1.Controls.Add(Python2VBText) Python2VBText.Text = Python2VBText.Text + "Usage: bbassign.py assignmentName" + vbNewLine + "Move all files in the current directory starting with a blank-converted" + vbNewLine + "assignmentName into directories assignmentName/user." + vbNewLine + "It is called from the directory into which assignmentName.zip" + vbNewLine + "has been unzipped (from a Blackboard assignment)." + vbNewLine + "The files from the zip archive have the assignment name modified" + vbNewLine + "if it contained blanks: the blanks are by replaced by underscores." + vbNewLine + "This program makes that substitution automatically. If there are" + vbNewLine + "several blanks in a row in the assignment name, I am not sure of the" + vbNewLine + "conversion algorithm:" + vbNewLine + "In that case check the prefix on all the zip file contents and make the" + vbNewLine + "program parameter be the actual assignment prefix used." else main(Environment.GetCommandLineArgs()(1)) ' sys.argv{0} is the program being run End If End If End Sub Public Function filesToMove(name) ' locally defined function, which can read variables ' return ' in the outer function End Function