Background:
260 students are divided into 52 Groups, with 1-6 students in each group. When submitting assignments, you only need one person to represent the entire team. There are multiple assignments, and each assignment can be submitted by different people.
The file name format is student ID _ name. I am only responsible for 9 of them, so I want to pick out 9 groups from 52 Groups, and retrieve 9 of them from more than 50 file names for each list of more than 40 people, too troublesome.
So I want to use a script to pick out the part I am responsible for, but it won't be the shell in windows, but it won't be in Linux ....
After learning python, I plan to use python for processing.
The Code is as follows:
Import osname = "homework2" ### select files in which Dir, the folder where the files to be processed are located ### student ID of the nine groups I am in charge, one teamtasks per line = (average, minimum, 111250222,111 128351018,111, 111250200, average, 111250244,111 101250038,111 111250223,111, 111250206, average, 111250232,111 rows, average, 111250189, average, 111250212, average, rows, average, minimum, 101250202,111 250202,111250228, 111250235,111250243, 111250252,111 250226,111250227, 111250229,111250230, 111250240) ### define a lookup function to find out whether the given student ID is in my responsibility list, #### the number in the tuples is returned. Otherwise,-1def find (Num): n = 0 while n <Len (tasks) is returned ): if (tasks [N] = num): Return N; n = n + 1 return-1 files = OS. listdir (name) ### list all files in the directory curdir = OS. path. join (OS. getcwd (), name) ### obtain the absolute path print curdirfor F in files: # print F num = (INT) (STR (f )[: 9]) #### the first 9 digits are student IDs res = find (Num) fp = OS. path. join (curdir, f) ### absolute path of the currently processed file # print FP if res =-1: ## not finds OS. remove (FP) # delete file to delete a file. The parameter must be the absolute path print "Remove" + F + "... "Else: ### Rename to add team ID fn =" Team _ "+ STR (INT) (RES/5 + 37 )) + "_" + F # Add the file name to the group prefix FNP = OS. path. join (curdir, FN) OS. rename (FP, FNP) ### rename the file print "RENAME" + FN # print filesprint "done. "temp = input (" press enter to exit... ")
It works well and is much more efficient than manual search...
Script is really easy to use... It is much simpler than C/C ++/Java ..