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
4
votes
2 answers

Nodejs: How can I optimize writing many files?

I'm working in a Node environment on Windows. My code is receiving 30 Buffer objects (~500-900kb each) each second, and I need to save this data to the file system as quickly as possible, without engaging in any work that blocks the receipt of the…
ACPrice
  • 667
  • 2
  • 10
  • 25
4
votes
2 answers

create-react-app exclude folder from triggering reload

I have a use case where I'm dynamically storing a pdf file in my public folder. public/print-preview/. The issue here is that the application reloads and the state gets lost after such a file was created and stored. How can I exclude such a folder…
4
votes
2 answers

P/Invoke call just stops

I'm trying to write data to a serial port via P/Invoke (explicitly not with the SerialPort-class). Here's what I have so far: [DllImport("kernel32", SetLastError = true)] static extern IntPtr CreateFile(string filename, // file name …
Papa Mufflon
  • 17,558
  • 5
  • 27
  • 35
4
votes
0 answers

WriteFile fails with ERROR_UNEXP_NET_ERR when writing to one file from several processes

I have several pc connected to one network. When I trying to write file with WriteFile function across network from several processes running on the different PC-s I getting ERROR_UNEXP_NET_ERR. Details: Several PC-s does they own calculations and…
Yuri Dolotkazin
  • 480
  • 4
  • 13
4
votes
1 answer

Fastest way to write raw data to hard drive (PhysicalDrive) on Windows 7

My company is developing a "fancy" USB Mass Storage Device running under Windows 7. The Mass Storage Client Driver that handles the reading and writing to the actual storage media on the client side is being written in C++. The problem we are…
Pungo120
  • 105
  • 1
  • 13
3
votes
1 answer

Does Polars module not have a method for appending DataFrames to output files?

When writing a DataFrame to a csv file, I would like to append to the file, instead of overwriting it. While pandas DataFrame has the .to_csv() method with the mode parameter available, thus allowing to append the DataFrame to a file, None of the…
3
votes
1 answer

How to append data to existing Parquet from Polars

I have multiple polars dataframes and I want to append them to an existing Parquet file. df.write_parquet("path.parquet") overwrites the existing parquet file. How can I append?
Jahspear
  • 151
  • 11
3
votes
0 answers

Uncaught (in promise) TypeError: r.writeFileSync is not a function in jspdf.js

I'm currently trying to add export to PDF functionality to my React application using jsPdf. My application uses Webpack5, which I know has removed a number of polyfills that existed in Webpack4. I originally encountered a buffer is not defined…
3
votes
1 answer

How to edit lines of a text file based on regex conditions?

import re re_for_identificate_1 = r"" with open("data_path/filename_1.txt","r+") as file: for line in file: #replace with a substring adding a space in the middle line = re.sub(re_for_identificate_1, " milesimo", line) …
3
votes
1 answer

WriteFile() blocks (writing from C++ client to C# server via named pipe )

I am stuck here, please help. I have a C# named pipe server, the pipe is created by: new NamedPipeServerStream(pipeName, PipeDirection.InOut, numThreads); In C++ I created the client like this: m_hPipe = CreateFile( strPipeName, …
Charlie
  • 764
  • 2
  • 13
  • 24
3
votes
3 answers

python jupyter magic %%writefile returns SyntaxError: invalid syntax

# [ ] The following program asks the user for a circle radius then display the area and circumference # Modify the program so it only displays the information when executed directly # The program should not display anything if it is imported as a…
Karen Jiang
  • 175
  • 1
  • 3
  • 12
3
votes
2 answers

How to print each element of an array in new line in txt file using javascript?

My result set is an array that returns from a function. ['item1','item2','item3','item4','item5','item6','item7','item8'] I am writing it into a file using fs.writeFile('out.txt', uniqueMatches, (err)=>{ if(err) throw err; …
Azim Shaik
  • 181
  • 1
  • 5
  • 14
3
votes
1 answer

does fs.writeFile() handles race condition in nodejs?

Before question, I hope u have basic knowledge on aws-sqs (not quite required though). Does fs.writeFile() handle race condition within itself ? I have come across an implementation like , function getMessage(){ sqs.receiveMessage( params ,…
drexdelta
  • 87
  • 3
  • 9
3
votes
1 answer

Can't write into a text file with for loop in c

I have an issue with writing strings into a txt file. My lines get overwritten every time. I use gcc -Wall -o filename filename.c to compile and ./filename 10 Berlin cat resultat.txt to execute. The txt file always has just one line (the last one)…
Marla
  • 101
  • 1
  • 11
3
votes
6 answers

How to check whether there's enough space before WriteFile in c in windows?

hPipe = CreateNamedPipe( lpszPipename, // pipe name PIPE_ACCESS_DUPLEX, // read/write access PIPE_TYPE_MESSAGE | // message type pipe PIPE_READMODE_MESSAGE | // message-read mode PIPE_WAIT, …
Alan
  • 5,029
  • 5
  • 32
  • 37
1 2
3
32 33