diff --git a/person.py b/person.py index 3b2781c6..3ebb4df0 100644 --- a/person.py +++ b/person.py @@ -637,7 +637,8 @@ def removeTagsForNickname(baseDir: str,nickname: str,domain: str,port: int) -> N domainFull=domain+':'+str(port) matchStr=domainFull+'/users/'+nickname+'/' directory = os.fsencode(baseDir+'/tags/') - for f in os.listdir(directory): + for f in os.scandir(directory): + f=f.name filename = os.fsdecode(f) if not filename.endswith(".txt"): continue diff --git a/posts.py b/posts.py index a9b2717a..4ae0a90a 100644 --- a/posts.py +++ b/posts.py @@ -378,7 +378,8 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None if boxname!='inbox' and boxname!='outbox': return boxDir = createPersonDir(nickname,domain,baseDir,boxname) - for deleteFilename in os.listdir(boxDir): + for deleteFilename in os.scandir(boxDir): + deleteFilename=deleteFilename.name filePath = os.path.join(boxDir, deleteFilename) try: if os.path.isfile(filePath): @@ -1749,8 +1750,9 @@ def createBoxBase(baseDir: str,boxname: str, \ # post filenames sorted in descending order postsInBoxDict={} postsCtr=0 - postsInPersonInbox=os.listdir(boxDir) + postsInPersonInbox=os.scandir(boxDir) for postFilename in postsInPersonInbox: + postFilename=postFilename.name if not postFilename.endswith('.json'): continue # extract the status number @@ -1763,8 +1765,9 @@ def createBoxBase(baseDir: str,boxname: str, \ if sharedBoxDir: handle=nickname+'@'+domain followingFilename=baseDir+'/accounts/'+handle+'/following.txt' - postsInSharedInbox=os.listdir(sharedBoxDir) + postsInSharedInbox=os.scandir(sharedBoxDir) for postFilename in postsInSharedInbox: + postFilename=postFilename.name statusNumber=getStatusNumberFromPostFilename(postFilename) if statusNumber: sharedInboxFilename=os.path.join(sharedBoxDir, postFilename) @@ -1967,7 +1970,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str if not os.path.isdir(archiveDir): os.mkdir(archiveDir) boxDir = createPersonDir(nickname,domain,baseDir,boxname) - postsInBox=os.listdir(boxDir) + postsInBox=os.scandir(boxDir) noOfPosts=len(postsInBox) if noOfPosts<=maxPostsInBox: return @@ -1975,6 +1978,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str postsInBoxDict={} postsCtr=0 for postFilename in postsInBox: + postFilename=postFilename.name if not postFilename.endswith('.json'): continue # extract the status number diff --git a/roles.py b/roles.py index f48be887..e5d84ae2 100644 --- a/roles.py +++ b/roles.py @@ -22,7 +22,8 @@ def clearModeratorStatus(baseDir: str) -> None: rarely when moderators are appointed or removed """ directory = os.fsencode(baseDir+'/accounts/') - for f in os.listdir(directory): + for f in os.scandir(directory): + f=f.name filename = os.fsdecode(f) if filename.endswith(".json") and '@' in filename: filename=os.path.join(baseDir+'/accounts/', filename)