|
| 1 | +# Get information about a file or directory |
| 2 | + |
| 3 | +You can get information about a file or directory using the `files.getInfo()` / `files.get_info()` methods. Information such as file name, type, and path is returned. |
| 4 | + |
| 5 | +### Getting information about a file |
| 6 | + |
| 7 | +<CodeGroup> |
| 8 | +```js |
| 9 | +import { Sandbox } from '@e2b/code-interpreter' |
| 10 | + |
| 11 | +const sandbox = await Sandbox.create() |
| 12 | + |
| 13 | +// Create a new file |
| 14 | +await sandbox.files.write('test_file.txt', 'Hello, world!') |
| 15 | + |
| 16 | +// Get information about the file |
| 17 | +const info = await sandbox.files.getInfo('test_file.txt') |
| 18 | + |
| 19 | +console.log(info) |
| 20 | +// { |
| 21 | +// name: 'test_file.txt', |
| 22 | +// type: 'file', |
| 23 | +// path: '/home/user/test_file.txt', |
| 24 | +// size: 13, |
| 25 | +// mode: 0o644, |
| 26 | +// permissions: '-rw-r--r--', |
| 27 | +// owner: 'user', |
| 28 | +// group: 'user', |
| 29 | +// modifiedTime: '2025-05-26T12:00:00.000Z', |
| 30 | +// symlinkTarget: null |
| 31 | +// } |
| 32 | +``` |
| 33 | +```python |
| 34 | +from e2b_code_interpreter import Sandbox |
| 35 | + |
| 36 | +sandbox = Sandbox() |
| 37 | + |
| 38 | +# Create a new file |
| 39 | +sandbox.files.write('test_file', 'Hello, world!') |
| 40 | + |
| 41 | +# Get information about the file |
| 42 | +info = sandbox.files.get_info('test_file') |
| 43 | + |
| 44 | +print(info) |
| 45 | +# EntryInfo( |
| 46 | +# name='test_file.txt', |
| 47 | +# type=<FileType.FILE: 'file'>, |
| 48 | +# path='/home/user/test_file.txt', |
| 49 | +# size=13, |
| 50 | +# mode=0o644, |
| 51 | +# permissions='-rw-r--r--', |
| 52 | +# owner='user', |
| 53 | +# group='user', |
| 54 | +# modified_time='2025-05-26T12:00:00.000Z', |
| 55 | +# symlink_target=None |
| 56 | +# ) |
| 57 | +``` |
| 58 | +</CodeGroup> |
| 59 | + |
| 60 | +### Getting information about a directory |
| 61 | + |
| 62 | +<CodeGroup> |
| 63 | +```js |
| 64 | +import { Sandbox } from '@e2b/code-interpreter' |
| 65 | + |
| 66 | +const sandbox = await Sandbox.create() |
| 67 | + |
| 68 | +// Create a new directory |
| 69 | +await sandbox.files.makeDir('test_dir') |
| 70 | + |
| 71 | +// Get information about the directory |
| 72 | +const info = await sandbox.files.getInfo('test_dir') |
| 73 | + |
| 74 | +console.log(info) |
| 75 | +// { |
| 76 | +// name: 'test_dir', |
| 77 | +// type: 'dir', |
| 78 | +// path: '/home/user/test_dir', |
| 79 | +// size: 0, |
| 80 | +// mode: 0o755, |
| 81 | +// permissions: 'drwxr-xr-x', |
| 82 | +// owner: 'user', |
| 83 | +// group: 'user', |
| 84 | +// modifiedTime: '2025-05-26T12:00:00.000Z', |
| 85 | +// symlinkTarget: null |
| 86 | +// } |
| 87 | +``` |
| 88 | +```python |
| 89 | +from e2b_code_interpreter import Sandbox |
| 90 | + |
| 91 | +sandbox = Sandbox() |
| 92 | + |
| 93 | +# Create a new directory |
| 94 | +sandbox.files.make_dir('test_dir') |
| 95 | + |
| 96 | +# Get information about the directory |
| 97 | +info = sandbox.files.get_info('test_dir') |
| 98 | + |
| 99 | +print(info) |
| 100 | +# EntryInfo( |
| 101 | +# name='test_dir', |
| 102 | +# type=<FileType.DIR: 'dir'>, |
| 103 | +# path='/home/user/test_dir', |
| 104 | +# size=0, |
| 105 | +# mode=0o755, |
| 106 | +# permissions='drwxr-xr-x', |
| 107 | +# owner='user', |
| 108 | +# group='user', |
| 109 | +# modified_time='2025-05-26T12:00:00.000Z', |
| 110 | +# symlink_target=None |
| 111 | +# ) |
| 112 | +``` |
| 113 | +</CodeGroup> |
0 commit comments