Questions tagged [writefile]

For questions about writing to a file. It could be referencing appending data, rewriting all existing content, or other related uses of functions that programmatically edit files. It is not limited to a certain language.

This tag is most often used when someone wants to add/insert content to a file programmatically. One example is in the Node JS function fs.writeFile, which is used to create files and write to them.

This is an example script which shows the usage of fs.writeFile to write a string to message.txt.

// Node JS

const fs = require('fs');
const data = new Uint8Array(Buffer.from('Hello Node.js'));

fs.writeFile('message.txt', data, (err) => {
  if (err) throw err;
  console.log('The file has been saved!');
});

Make sure to pair this tag with a language tag as is generally not specific enough to describe a complete question.

494 questions
1
vote
1 answer

Is there a good way to save these as their own files during this loop and then to plot them in different colors?

list_of_coordinates = [] i = 0 while i < len(list_of_structures): for models in list_of_structures: for model in models: chains = model.get_chains() for chain in chains: residues =…
Sam Taylor
  • 37
  • 6
1
vote
1 answer

Unable to read data from fixture file after writing it

I'm writing a URL with an ID in a .json file that I'm extracting from the API, but the problem is that the cy.log() is printing the data before it is wrote in the file. Because the AppelData.json has the written data, but cy.log() prints…
1
vote
1 answer

having trouble with the README Generator but for some reason fs.writeToFile is not a function

This is the code that is causing the error: const writeToFile = data => { return new Promise((resolve, reject) => { fs.writeFile('./dist/generated-README.md', data, err => { if (err) { reject(err); …
1
vote
1 answer

read file and write to file error in python

well I'm getting this error when I try to use login option "local variable 'register' referenced before assignment" def logins(): choice = int(input("1) Do you want to Login?: \n2) Do you want to Register?: \n")) if choice == int(2): …
1
vote
1 answer

Understanding ERROR_SHARING_VIOLATION in fasm x86

From my understanding if the share mode is set to 0, I will not be able to open the file again. By default I've set it to 3, but even setting it to 2 ( FILE_SHARE_WRITE ) outputs the same error. So that makes me think that the parameters are…
Germ
  • 117
  • 6
1
vote
1 answer

Can I use a file handles in IO completion ports with and without overlapped I/O

I want to use ReadFile() (overlapped) on a named pipe in message mode in combination with an I/O completion port. So, I have multiple threads waiting for ReadFile() to receive data. The awaken thread will process the message and may call WriteFile()…
xMRi
  • 14,982
  • 3
  • 26
  • 59
1
vote
1 answer

How can I write every list from a nested list separately to a file?

I am trying to write every list from a nested list to the same file. However I want every list to start on a newline. I've made this and it works, but it's very inefficient and looks bad: appendFile "scraped.txt" (show (take 1 l)) appendFile…
1
vote
0 answers

NodeJS: Every audio file created through fs.writeFile and Blob has excessive length

I'm creating an app which needs to take the user's voice and convert it to text, but the audio file seems to have something wrong with the length after it's creation. Here is how I'm gathering the audio and converting the data to a Blob. I'm just…
1
vote
3 answers

Cypress push value in json array

I would like to compile a list and push them into a json array in Cypress. This is what the json out put is supposed to look like: [ { "role": "Administrator", "scenarios": [ "clients_a", "clients_d", "clients_f", …
cypher_null
  • 632
  • 8
  • 22
1
vote
1 answer

How to properly write the values of an array into a JSON file using writeFile in Cypress?

I wanted to write the values of an array into a JSON file by using writeFile . console.log(category); cy.writeFile('cypress/fixtures/actionsName.json', category); I've outputted the values of the category array. See below My expected contents of…
Harvey
  • 399
  • 4
  • 15
  • 31
1
vote
3 answers

add keys to a json file, remove duplicates and write to json file in javascript

I want to add data from another Json file to another without overwriting the existing one. I just can't get any further, the console always gives me the following: Console output Data string [ "follow1", "follow2", "follow3", …
da f
  • 13
  • 2
1
vote
2 answers

How to write multiple text files from a text file in C++?

I have a txt file that has 500,000 lines, and each line has 5 columns. I want to read data from this file and write it into different 5000 txt files that have 100 lines each, starting from the first line to the last of the input file. Also, the…
kingsley
  • 27
  • 5
1
vote
0 answers

win32 what happens if app crashed/BSODed while running WriteFile having unbuffered and write_THROUGH flags on NTFS

i'm overwriting to file in 10mb chunks by WriteFile API handle is opened using FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH |FILE_FLAG_RANDOM_ACCESS flags in CreateFile my question is : what happens to the chunk if my app…
morthy
  • 11
  • 3
1
vote
0 answers

using createWriteStream with xmlbuilder consume a lot of ram

We need to create a XML file with some items in there, so we are using xmlbuilder module for this. The array have 50k of products, the memory usage processing the file is 200mb of ram, but at the moment of creating the file with xmlbuilder, the…
1
vote
4 answers

Writing files to USB stick causes file corruption/lockup on surprise removal

I'm writing a background application to copy files in a loop to a USB stick with the "Optimize for quick removal" policy set. However, if the stick is removed part way through this process (specifically in the WriteFile() call below, which returns…
Agnus