file-io

How to read a list of filenames from a text file and open them in C++?

孤街浪徒 提交于 2019-12-25 06:06:53
问题 I have a list of files stored in a text file. I read the file line by line and store them in a string array. The file list looks like this: 04_02_1310.csv 04_03_1350.csv 04_04_0421.csv 04_05_0447.csv and so on. Let's call my string array filelist[i] Assuming I am trying the open the first file in the list: inputFile.open(filelist[0].c_str()); // This cannot open file the file cannot be opened. If i place the file name in quotation marks, everything works out fine: inputFile.open("04_02_1310

Python + open() + write on Windows - permission issue (IOError) for file created on OS X

随声附和 提交于 2019-12-25 05:36:08
问题 (I asked this previously, but have since accepted that it is not an issue with openpyxl , so changing tack) Given an xlsx created on OS X, I open it for writing on that platform using openpyxl load_workbook() . I add some data, then I save it using Workbook.save() (to the same file). All good on OS X, but when the program, and the XLSX, are transferred onto a Windows machine and executed, I get: c:\Users\Me\Desktop\ROI>python roi_cut7.py > log.txt Traceback (most recent call last): File "roi

Program Crashing while trying to open a .txt file

风流意气都作罢 提交于 2019-12-25 05:26:14
问题 When I try to run my program it crashes right of the start. The problem is my input from file, I can write to the file fine. Can someone explain why this code wouldn't work?? StringList::StringList() { pTop=NULL; pBottom=NULL; ifstream in; in.open("read.txt"); StringListNode * pCurrent; pCurrent = new StringListNode; pCurrent = pTop; while(!in.eof()) //reads it till the end of file { in >> pCurrent->data; pCurrent = pCurrent->pNext; } in.close(); } This Output to the file works fine. I

Double free error on fclose() on previously closed file handle

强颜欢笑 提交于 2019-12-25 05:25:09
问题 I have a class that contains file handle fHandle that points to an open file. Now, it can be closed by any one of the multiple routines and that is based on dynamic run of the program. To be sure that a file is indeed closed, I put simple snippet in my destructor: if(fHandle!=NULL) fclose(fHandle); . Turns out, if one of the routines had previously closed this file, then the running the destructor snippet causes double free operation and I get **glib detected** error message. How do I make

Why does shell redirection fail when using echo/sudo?

强颜欢笑 提交于 2019-12-25 05:18:11
问题 I have a simple script which is behaving un-expectedly. path='/usr/local/bin/new_script' content='#!/bin/bash\nls' sudo echo -e "$content" > "$path" Raises Error: bash: /usr/local/bin/new_script: Permission denied What am I doing wrong ? 回答1: You can do the redirection with: sudo sh -c "echo -e '$content' > $path" 回答2: You don't have write access to either the file /usr/local/bin/new_script or the directory /usr/local/bin Executing the echo command with sudo doesn't help, as echo just writes

Find files/folders that are modified after a specific date in Python

风格不统一 提交于 2019-12-25 05:01:30
问题 Problem ; find files/folders that are changed after a specific date from a directory structure and copy these to another location (as stated clearly in title as well) (: By the following ; def mod(): """Find files modified today, given a file path.""" latest = 0 now = time.strftime('%Y-%m-%d', time.localtime()) dir = "/home/y33t/" for fname in os.listdir(dir): if fname.endswith(''): modtime = os.stat(os.path.join(dir, fname)).st_mtime if modtime > latest: latest = modtime out = time.strftime(

remove whitespace and add character in txt

别说谁变了你拦得住时间么 提交于 2019-12-25 04:39:24
问题 I have a problem with MATLAB code. What I want is that you delete all the blanks in a. Txt (example file below) and that one could add character ||||||||||||| to the end of each line. Example txt: *|V|0|0|0|t|0|1|1|4|11|T4|H01||||||| P|40|0.01|10|1|1|0|40|1|1|1||1|*||0|0|0|| *|A1|A1|A7|A16|F|F|F|F|F|F|F|||||||| *|cod. serv|area |codice |nome|tnom|tmin|tmax|pc|qc|cond|susc|||||||| *|Ciao questa rete ha 32 nodi *|||||kV|kV|kV|MW|MVAR|S|S|||||||| N|I|01|H01N01|H01N01|132|125.4|138.6|0|0|||||||||

Read file from position

[亡魂溺海] 提交于 2019-12-25 04:18:09
问题 FileStream infile = new FileStream(@"C:\Users\John\Desktop\ProjectNew\nov.txt", FileMode.Open, FileAccess.Read); int position = x.Length; infile.Seek(position, SeekOrigin.Begin); But Seek method returns number. How to read the file 'infile' from position to end in a string? 回答1: Is this what you're after? Assuming you wanted to start reading from position 100... using (FileStream fs = new FileStream(@"file.txt", FileMode.Open, FileAccess.Read)) { fs.Seek(100, SeekOrigin.Begin); byte[] b = new

Writing data to jTable using file i/o

ぃ、小莉子 提交于 2019-12-25 04:14:50
问题 can you please look at my code and explain why my program is writing more entries to the array list? package pkg842994_ranganathan_vocabtrainerdossier; import javax.swing.JLabel; import javax.swing.JFrame; import java.util.ArrayList; import javax.swing.JOptionPane; public class EditLibraryUI extends javax.swing.JFrame { //Declare array list as public static because it needs to be accessed //in other classes public static ArrayList<VocabWord> LibraryWordsList = new ArrayList<VocabWord>(); int

open with O_RDWR — how to overwrite?

感情迁移 提交于 2019-12-25 03:58:09
问题 I want to read a file and change its content and write it back to the file. I use open to read a file as follows: bfd = open(m_file_name.c_str(), O_RDWR) But when I write, it is kinda append it to the old one. How can I overwrite it? 回答1: You can use lseek(2) bfd = open(m_file_name.c_str(), O_RDWR); // read your file lseek(bfd, 0, SEEK_SET); // do whatever manipulation & write file If your file is now less in size than the original, you will need to truncate the size to the new size, or you