This question already has answers here:
Renaming files using node.js
(5 answers)
Closed 3 years ago.
I have some files that I need to copy in another folder and then renaming all of them one by one. Is there any solution to rename all those files in the new folder one by one in synchronous way?
The function you're looking for is
fs.renameSync(old_file_path, new_file_path)
You can find it in the node documentation here
Remember you'll need to require in filesystem with const fs = require('fs') as well.
Related
This question already has answers here:
How to get the path of current worksheet in VBA?
(5 answers)
Closed 6 days ago.
I need to access the windows directory in my project.
How can I get the windows path? I mean how can I get the path, which the Windows installed in it?
Thanks
I searched the web a lot, but nothing found.
You can use the "environ" function to retrieve the directory, as I show below:
Dim windowsDir As String
windowsDir = Environ("windir")
This question already has answers here:
How to overwrite the output directory in spark
(9 answers)
Closed 4 years ago.
Writing files via rdd.saveAsPickleFile(output_path) fails if the directory already exists. While that is a good thing to avoid accidental file deletion, I was wondering if there was an option to explicitly overwrite the folder/the files? Similarly to dataframes:
df.write.mode('overwrite').format('json').save(output_path)
Note: the following two questions here and here have asked this before but not received explicit answers.
If you would like to explicitly delete the folder where your pickle file is created each time you run your script. You could delete the directory at output_path as described in https://stackoverflow.com/a/10840586/5671433 before you call
df.write.mode('overwrite').format('json').save(output_path)
This question already has answers here:
How to access internal resources from background.js
(3 answers)
Closed 6 years ago.
Every page on the internet seems to suggest a different option for this, and who knows what's deprecated and what isn't. What's the "correct" way to read a file from within the extension bundle? I don't want to inline the data into the script files themselves, both because it's awful practice and because it consumes an unnecessary amount of memory.
Fetch is the newest and easiest. It works in all cases except getting a list of the packaged files at runtime, which requires chrome.runtime.getPackageDirectoryEntry.
fetch("manifest.json").then(function(response) {
return(response.json())
}).then(function(manifest) {
console.log(manifest)
})
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
This question already has answers here:
How can I make Node.js 'require' absolute? (instead of relative)
(39 answers)
Closed 8 years ago.
I'm creating an express 4 project and many of my files are nested within folders. Unfortunately I using a lot of :
var x = require('../../../../file');
I'm thinking I can avoid this if I have access to the base url of the project, but I'm seeing that using a global variable isn't a good idea. What's the best way to tackle this?
If you want directory of the root script from which the node process started, you can get it like this:
var root = require.main.filename.slice(0,require.main.filename.lastIndexOf('/'))
or, as #ChiChou suggested:
var root = require('path').dirname(require.main.filename)
This assumes that the main script (or any other script that requires your code) is run from the root directory.
You can use this root as your "base url".
This question already has answers here:
A tool to add and complete PHP source code documentation [closed]
(9 answers)
Closed 9 years ago.
im looking for a way to add some docblocks to a new .php file, so i can have it add the description, package name, author , etc to a new file.
i have been searching for a couple days and I dont see any results on how to add just to 1 .php file, maybe a console command or another utility?
Some sort of generator
Try PHP_DocBlockGenerator from PEAR -- http://pear.php.net/package/PHP_DocBlockGenerator