Distinguish Between Files and Folders/Directories [VD16]

Distinguish Between Files and Folders/Directories [VD16]

Tip VD16

While “files” and “folders/directories” have some similar operations that can be performed on them, they are in many ways different kinds of entities and cannot often be interacted with in the same way. Therefore, to avoid mix-ups, best to clearly identify which variables represent files versus which variables represent folders/directories.

See examples below:

There may be cases where you have a variable that can hold either a file or a folder/directory. In this case, there are several options that can help make indicate this:

  • Include “file or folder” or “file or directory” in the variable name - This can be one of the strongest ways to make sure a variable name is clear as potentially holding either kind of item. However, if you need to include a bunch of other words in a variable name to make it specific enough, then including a phrase like “file or directory” might make a variable name long enough to become unwieldy.

  • Use “directory entry” instead - This is a somewhat technical term for a word that can apply to any kind of entity that can be in a directory.

  • Use “item” instead - This is the term that Windows' File Explorer uses when viewing how many things are in a folder. It’s a less technical term than “directory entry,” though you may need to include extra words/phrases in the name to make it specific enough (ex. item_in_folder).

Code in the zone ad.png