CleanFolderData (Version 2)

A module to take a folder, remove some random and unneccessary files, and give you a list / array of the outcome.

from PythonFunctions.CleanFolderData import Clean
clean = Clean()

Usage

clean.clean(path, reserved, *, includeHidden)

The main function, Even can go through here of through one function at a time. This function does add some small things compaired to the other functions however.

Parameters
  • path (str) – The path of the folder to “clean”

  • reserved (List[str]) – Optional, A list of files that are not included

  • includeHidden (bool) – Optional, include files that have either ‘.’ or ‘__’ to begin with. Defaults to False.

Returns

A list of files that have been “cleaned”

Return type

List[str]

from PythonFunctions.CleanFolderData import Clean
clean = Clean()
result = clean.clean(".", ["secret.txt"])
print(result) # Excepts everything but having hidden files and secret.txt in a list

GetData

clean.GetData(path)

Basically does the same thing as os.listdir(path).

Parameters

path (str) – The path to list the information of

Returns

A list of files from os.listdir, or path if it is a list

Return type

List[str]

Note

If the path could not be found, then an empty list is returned

from PythonFunctions.CleanFolderData import Clean
clean = Clean()
result = clean.GetData(".")
print(result) # Pretty much prints os.listdir(".")

RemoveHidden

clean.RemoveHidden(data)

Removes all hidden files, those that starts with . or __

Parameters

data (List[str]) – The data to remove hidden files from

Returns

A list of files without hidden files

Return type

List[str]

from PythonFunctions.CleanFolderData import Clean
clean = Clean()
result = clean.RemoveHidden(["a", "b", ".hidden", "__pycache", "", "hidden.txt"])
print(result) # ["a", "b", "hidden.txt"]

RemoveReserved

clean.RemoveReserved(data, reserved)

Removes all files in reserved from data.

Parameters
  • data (List[str]) – The data to remove files from

  • reserved (List[str]) – The files to remove from data

Returns

A list of files without the files in reserved

Return type

List[str]

Note

You can use wildcards! *.txt will remove all files ending in .txt

from PythonFunctions.CleanFolderData import Clean
clean = Clean()
result = clean.RemoveReserved(["a", "b", "hidden.txt"], ["hidden.txt"])
print(result) # ["a", "b"]