-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniqueIDs.py
65 lines (56 loc) · 1.58 KB
/
uniqueIDs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#author: dns43
#this script walks threw a specified directory
#and makes all filenames unique
#by adding a number to the end of the filename
#each number is added to 1 .ast, 1 .js, and 1 .txt file before it is increased
#this circumvents multiply defined instace names,
#when applying the codestylometry project to the dataset
import zipfile
import os
folderlist = []
filelist = []
path = "C:\\Users\\dns43\\Desktop\\Drexel\\webscraper\\testset"
#dns43: recursively walks through folders and creates a list of .zip files
def collectFiles(pfad):
for entry in os.scandir(pfad):
#print(entry.path)
if entry.is_dir():
folderlist.append(entry.path)
collectFiles(entry.path)
elif entry.is_file():
filelist.append(entry.path)
collectFiles(path)
#dns43: some verbose debug information
print('Folders:')
print(len(folderlist))
print('Files:')
print(len(filelist))
#dns43: i is used as an index
i=0
#dns43: c is the counter, eventually attached to the filename
c=0
for file in filelist:
#dns43: kind of a switch case construct
#dns43: to make sure filenames stay in relation to each other
#dsn43: otherwise you would have "main1.js, main2.ast, main3.txt"
if ".js" in file:
t=file[:-3]+str(i)+file[-3:]
os.rename(file, t.replace(" ", ""))
print(t.replace(" ", ""))
c=c+1
if c%3 == 0:
i=i+1
if ".ast" in file:
t=file[:-4]+str(i)+file[-4:]
os.rename(file, t.replace(" ", ""))
print(t.replace(" ", ""))
c=c+1
if c%3 == 0:
i=i+1
if ".txt" in file:
t=file[:-4]+str(i)+file[-4:]
os.rename(file, t.replace(" ", ""))
print(t.replace(" ", ""))
c=c+1
if c%3 == 0:
i=i+1