本文整理匯總了TypeScript中fs-extra.rename函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript rename函數的具體用法?TypeScript rename怎麽用?TypeScript rename使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了rename函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getNewPath
getNewPath('Enter a new name', data.cwd, newPath => {
fs.rename(file.path, newPath, err => {
if (codeFileNav.checkError(err)) { return; }
codeFileNav.showFileList();
});
});
示例2: clearNodeModules
async function clearNodeModules(): Promise<void> {
const logger = getLogger();
if (isRsyncModeEnabled) {
return;
}
logger.trace(`moving node_modules to node_modules.bak.0`);
let bodyCount = 0;
let bakDirname;
while (true) {
bakDirname = `${nodeModules}.bak.${bodyCount}`;
logger.trace(`moving node_modules to ${bakDirname}`);
try {
await fsExtra.stat(bakDirname);
logger.trace(`${bakDirname} already exists; incrementing`);
bodyCount++;
} catch (err) {
if (err.code && err.code === 'ENOENT') {
await fsExtra.rename(nodeModules, bakDirname);
logger.trace(`move was successful; removing ${bakDirname} without blocking`);
return fsExtra.remove(bakDirname);
}
}
}
}
示例3: reject
return new Promise<void>((resolve, reject) => {
fs.rename(from, to, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例4: cleanAsync
async function cleanAsync(series: mio.IScraperSeries) {
let chapterPaths = series.chapters.map(seriesChapter => shared.path.normal(series.providerName, series.title, seriesChapter.name + shared.extension.cbz));
let fileNames = await fs.readdir(shared.path.normal(series.providerName, series.title));
let filePaths = fileNames.map(fileName => shared.path.normal(series.providerName, series.title, fileName));
for (let filePath of filePaths) {
let fileExtension = path.extname(filePath);
if (fileExtension === shared.extension.cbz && chapterPaths.indexOf(filePath) === -1) {
await fs.rename(filePath, filePath.substr(0, filePath.length - fileExtension.length) + shared.extension.del);
}
}
}
示例5: function
fs.stat(newPath, function (err, stats) {
if (err && err.code === "ENOENT") {
return fs.rename(oldPath, newPath, callback);
}
if (err) {
return callback(err);
}
err = new Error("EEXIST: file already exists: " + newPath);
err.code = "EEXIST";
callback(err);
});
示例6: archiveAsync
await mio.usingAsync(seriesChapter.iteratorAsync(), async iterator => {
try {
await archiveAsync(chapter, iterator);
chapter.finalize();
await fs.rename(chapterPath + shared.extension.tmp, chapterPath);
console.log(`Finished ${seriesChapter.name} (${timer})`);
} catch (error) {
await fs.unlink(chapterPath + shared.extension.tmp);
throw error;
} finally {
chapter.abort();
}
});
示例7: setupFixtureRepository
export async function setupFixtureRepository(
repositoryName: string
): Promise<string> {
const testRepoFixturePath = Path.join(
__dirname,
'..',
'fixtures',
repositoryName
)
const testRepoPath = _temp.mkdirSync('desktop-git-test-')
await FSE.copy(testRepoFixturePath, testRepoPath)
await FSE.rename(
Path.join(testRepoPath, '_git'),
Path.join(testRepoPath, '.git')
)
const ignoreHiddenFiles = function(item: KlawEntry) {
const basename = Path.basename(item.path)
return basename === '.' || basename[0] !== '.'
}
const entries: ReadonlyArray<KlawEntry> = klawSync(testRepoPath)
const visiblePaths = entries.filter(ignoreHiddenFiles)
const submodules = visiblePaths.filter(
entry => Path.basename(entry.path) === '_git'
)
for (const submodule of submodules) {
const directory = Path.dirname(submodule.path)
const newPath = Path.join(directory, '.git')
await FSE.rename(submodule.path, newPath)
}
return testRepoPath
}
示例8: reject
return new this.$q<Models.IDocument>((resolve, reject) => {
if (!fs.existsSync(oldPath)) {
reject("Document does not exist");
return;
}
if (fs.existsSync(document.path)) {
reject("New filename already exists");
return;
}
fs.rename(oldPath, document.path, (err) => {
if (err) {
reject(err);
}
else {
resolve(document);
}
});
});
示例9: reject
return new this.$q<Models.IFolder>((resolve, reject) => {
if (!nodeFs.existsSync(folder.path)) {
reject("Folder does not exist");
return;
}
var parentPath = nodePath.dirname(folder.path);
var newPath = nodePath.join(parentPath, name);
if (nodeFs.existsSync(newPath)) {
reject("Folder with name " + name + " already exists");
return;
}
nodeFs.rename(folder.path, newPath, (err) => {
if (err) {
reject(err);
}
else {
resolve(new Models.NodeFolder(newPath));
}
});
});
示例10: downloadSdk
export default async function downloadSdk() {
const alreadyDownloaded = await fs.pathExistsSync(SDK_DIR);
if (alreadyDownloaded) {
console.log('VK iOS SDK already downloaded');
return;
}
console.log(`Downloading VK iOS SDK as ${SDK_ZIP}`);
const response = await axios.get(`https://api.github.com/repos/VKCOM/vk-ios-sdk/releases`);
const data: GithubRelease[] = response.data;
const zip = await axios.get(data[0].zipball_url, { responseType: 'arraybuffer' });
await fs.writeFile(SDK_ZIP, zip.data);
let sdkDir = '';
console.log(`\nExtracting VK iOS SDK to ${SDK_DIR}`);
try {
await extract(
SDK_ZIP,
{
onEntry: (entry: any) => sdkDir = sdkDir || entry.fileName,
dir: process.cwd(),
},
);
await fs.rename(sdkDir, SDK_DIR);
console.log('\nDone\n');
} catch (err) {
console.warn(`Failed to download and extract VK iOS SDK: ${err}`);
} finally {
try {
await fs.remove(SDK_ZIP);
} catch (e) {
console.warn('Failed to unlink some temporary/unnecessary files');
}
}
}