'Uploaded a .zip and need to remove the directories where the 4th character in the directory name is not the character S

Have a .zip folder that contains folders and files within each folder.

import zipfile as zf
files = zf.ZipFile("FileName.zip", 'r')
files.extractall()
files.close()

Then I need to count the number of folders within the .zip folder so I execute this:

import os
os.getcwd()
count = 0
d = "FileName"
for path in os.listdir(d):
        count += 1
print (count)

Next is where I get stuck... I need to remove the directories where the 4th character in the directory name is not the character S. Each folder within the .zip folder has a file name full of characters.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source