codebase.files
property will only return SourceFile objects. To include non-code files the extensions='*'
argument must be used.
codebase.get_file
, files ending in .py, .js, .ts, .jsx, .tsx
are returned as SourceFile objects while other files are returned as File objects.
Furthermore, you can use the isinstance
function to check if a file is a SourceFile:
.functions
(SourceFile / Directory) - All Functions in the file/directory.classes
(SourceFile / Directory) - All Classes in the file/directory.imports
(SourceFile / Directory) - All Imports in the file/directory.get_function(...)
(SourceFile / Directory) - Get a specific function by name.get_class(...)
(SourceFile / Directory) - Get a specific class by name.get_global_var(...)
(SourceFile / Directory) - Get a specific global variable by nameEditable
objects, just like Functions and Classes.
File.search
- Search for all functions named “main”File.edit
- Edit the fileFile.replace
- Replace all instances of a string with another stringFile.insert_before
- Insert text before a specific stringFile.insert_after
- Insert text after a specific stringFile.remove
- Remove a specific string.edit(...)
method or .replace(...)
method.
File.update_filepath()
, File.rename()
, and File.remove()
:
Directories
expose a similar API to the File class, with the addition of the subdirectories
property.