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

How can WriteFile succeed without writing any data?

I'm calling WriteFile to send data to a modem: BOOL writeResult = WriteFile(m_hPort, p_message, length, &numOut, NULL); where: m_hPort is a valid HANDLE p_message is an unsigned char* containing ate0\r length is an int with a value of 5 numOut is…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
1
vote
3 answers

saving file to network

I have a file that's about 7 MB that saves to my local share in a matter of seconds. However, saving that file to a network location takes minutes. I'm wondering what I can do to speed this up. Here are my current options: Save the data to a…
Michael Kelley
  • 3,579
  • 4
  • 37
  • 41
1
vote
1 answer

Node.js: should reject with an error if the passed data is invalid

I'm getting a problem while running the test cases using the node.js application where I'm creating a directory if not exists, writing the json and reading the file. Here's the Working Demo Link It's throwing the below error even after handling the…
Subhojit
  • 1,389
  • 8
  • 19
  • 33
1
vote
0 answers

Read Write file in next js api

I want to Write a example.txt file in a __dirname + "/testfolder/example.txt" but next js build version not allow to write. so how can I solve this problem ? When I try to Write any file the it's log Error: EISDIR: illegal operation on a directory,…
1
vote
1 answer

Interference Between a Structure's :print-function and *print-readably* in Common Lisp?

I'm trying to readably print a common lisp structure to a file so it can be read back in later. It appears SBCL has some rather sophisticated built-in facilities for readably printing complex objects, which may obviate having to write specialized…
davypough
  • 1,847
  • 11
  • 21
1
vote
1 answer

conditional statement checking if node js filesystem.writefile is a success

Can it be said that fs promise writeFile and fs writeFileSync are the same thing? or rather, would behave the same way? const fs = require('fs') const fsProm = require ('fs').promises //write file sync fs.writeFileSync(filePath, data) write file…
payiyke
  • 19
  • 3
1
vote
3 answers

perl add line into text file

I am writing a script to append text file by adding some text under specific string in the file after tab spacing. Help needed to add new line and tab spacing after matched string "apple" in below case. Example File: apple original…
peace
  • 149
  • 7
1
vote
1 answer

Cannot write the full buffer with WriteFile function

I am trying to use WriteFile to write a simple text in a .TXT file. Here's my declaration: // For WriteFile fuction BOOL writeFile; LPCVOID textToWrite = L"SakyLabs: Hello, MDE."; DWORD numberOfBytes = (DWORD)wcslen(textToWrite); …
Sergio Calderon
  • 837
  • 1
  • 13
  • 32
1
vote
1 answer

Haskell - How do I write a tuple list to a text file

I get text from .txt, process it. I get vowels and their number from the text. I cannot write tuple list [(Char, Int)] to text file. I want to make each line to have a letter and its number, but I can't write it at all. ` import Data.List import…
1
vote
0 answers

File transfer to RStudio Server

How can I send files from a local computer to a virtual machine with RStudio Studio? Of course, I can use the 'Upload' button but I would like to load something regularly on the virtual machine, how different I can do it?
Zizou
  • 503
  • 5
  • 18
1
vote
1 answer

Node.js how to cancel a WriteFile operation

Is there a way to cancel a WriteFile operation? example: await promises.writeFile(path, data)
imvenx
  • 194
  • 3
  • 10
1
vote
1 answer

How to replace a txt file content?

I have a banned_word list banned=["things", "show","nature","strange image"], ,and I need to read a forum message txt file and replace all the banned words in the forum file by same length asterisks. This is the forum file Forum ONE Are things…
Lu Yubing
  • 11
  • 2
1
vote
1 answer

check the file and add a new string

My goal is to check all the lines of the file (there is one word per line) and if the string is not present in the whole file, I have to add it at the bottom. The problem is that the "is_Cursor" loop changes my "tx.Data" and therefore I have to give…
1
vote
1 answer

Error trying to use writeFile with NodeJS

I am trying to write a function using fs.writeFile but I am getting this error. TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined I am not so familiar with JS so I'd appreciate the help. My function: write(fileName,…
laura
  • 23
  • 3
1
vote
1 answer

How do I empty out a file's text into another file?

I am trying to make my code so that it simulates a chat. So far, I have no problem doing that, but the problem is, I want to make it so that when the chat reaches a certain amount of lines, it purges the chat and empties out the content of the text…