(newName: string, onError?: (error: any) => any)
| 120 | } |
| 121 | |
| 122 | public renameSync(newName: string, onError?: (error: any) => any): void { |
| 123 | if (this._isKnown) { |
| 124 | if (onError) { |
| 125 | onError(new Error('Cannot rename known folder.')); |
| 126 | } |
| 127 | |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | const localError = function (error) { |
| 132 | if (onError) { |
| 133 | onError(error); |
| 134 | } |
| 135 | |
| 136 | return null; |
| 137 | }; |
| 138 | |
| 139 | const fileAccess = getFileAccess(); |
| 140 | // call rename for FileSystemAccess29 |
| 141 | if ((<any>fileAccess).__skip) { |
| 142 | fileAccess.rename(this.path, newName, localError); |
| 143 | const fileInfo = getFileAccess().getFile(this.path, null); |
| 144 | if (fileInfo) { |
| 145 | this._name = fileInfo.name; |
| 146 | this._extension = fileInfo.extension; |
| 147 | } |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | const parentFolder = this.parent; |
| 152 | if (!parentFolder) { |
| 153 | if (onError) { |
| 154 | onError(new Error('No parent folder.')); |
| 155 | } |
| 156 | |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | const path = parentFolder.path; |
| 161 | const newPath = fileAccess.joinPath(path, newName); |
| 162 | |
| 163 | fileAccess.rename(this.path, newPath, localError); |
| 164 | this._path = newPath; |
| 165 | this._name = newName; |
| 166 | |
| 167 | if (this instanceof File) { |
| 168 | this._extension = fileAccess.getFileExtension(newPath); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | get name(): string { |
| 173 | return this._name; |
no test coverage detected