file-io

How to remove multiple files in C using wildcards?

拟墨画扇 提交于 2021-01-26 22:57:27
问题 Is there any way in C to remove (using remove() ) multiple files using a * (wildcards)? I have a set of files that all start with Index. For example: Index1.txt , Index-39.txt etc. They all start with Index but I don't know what text follows. There are also other files in the same directory so deleting all files won't work. I know you can read the directory, iterate each file name, read the the first 5 chars, compare and if it fits then delete, but, is there an easier way (this is what I

Python's read and write add \x00 to the file

泪湿孤枕 提交于 2021-01-26 14:46:23
问题 I have come across a weird problem when working with files in python. Let's say I have a text file and a simple piece of code that reads the contents of the file and then rewrites it with unaltered contents. File.txt This is a test file Python code f=open(File.txt,'r+') data=f.read() f.truncate(0) f.write(data) f.close() After running the above code File.txt seems to be the same. However, when I opened it in a hex editor I was surprised to see lots of \x00 (NULL) bytes before the actual

Modify a csv file line by line

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-23 06:35:20
问题 I have a big file that I want to modify every line in it. I want to use PHP to do it quickly : My file is CSV file ; 20010103,02,00,00,0.9496 20010103,03,00,00,0.9504 20010103,04,00,00,0.9499 I want to make it like this to be able to use it late with Highchart: [Date.UTC(2001,01,03,02,00,00),0.9496], [Date.UTC(2001,01,03,03,00,00),0.9504], [Date.UTC(2001,01,03,04,00,00),0.9499], How canI loop every line and make this modification ? 回答1: See the fgetcsv and fputcsv PHP functions. It will

Modify a csv file line by line

南笙酒味 提交于 2021-01-23 06:33:54
问题 I have a big file that I want to modify every line in it. I want to use PHP to do it quickly : My file is CSV file ; 20010103,02,00,00,0.9496 20010103,03,00,00,0.9504 20010103,04,00,00,0.9499 I want to make it like this to be able to use it late with Highchart: [Date.UTC(2001,01,03,02,00,00),0.9496], [Date.UTC(2001,01,03,03,00,00),0.9504], [Date.UTC(2001,01,03,04,00,00),0.9499], How canI loop every line and make this modification ? 回答1: See the fgetcsv and fputcsv PHP functions. It will

Modify a csv file line by line

半世苍凉 提交于 2021-01-23 06:33:53
问题 I have a big file that I want to modify every line in it. I want to use PHP to do it quickly : My file is CSV file ; 20010103,02,00,00,0.9496 20010103,03,00,00,0.9504 20010103,04,00,00,0.9499 I want to make it like this to be able to use it late with Highchart: [Date.UTC(2001,01,03,02,00,00),0.9496], [Date.UTC(2001,01,03,03,00,00),0.9504], [Date.UTC(2001,01,03,04,00,00),0.9499], How canI loop every line and make this modification ? 回答1: See the fgetcsv and fputcsv PHP functions. It will

Does Python support zero-copy I/O?

被刻印的时光 ゝ 提交于 2021-01-21 03:45:41
问题 I have two open file objects, dest and src . File object dest is opened for writing, with the seek position placed at some offset within the file, and file object src is opened for reading. What I need to do is simply read from the current position in src to EOF and transfer the contents to dest as quickly as possible. If I were programming in Java, I could utilize the FileChannel#transferTo() method to perform zero-copy file I/O. Does Python also support zero-copy? 回答1: Since version 3.3,

How to Append a json file without disturbing the formatting

♀尐吖头ヾ 提交于 2020-12-30 06:13:44
问题 I'm working on a file to add/retrieve the data. The data format is JSON . I'm a newbie. I'm using JSON.NET to serialize and deserialize the data. this is the JSON format { "EmpId": 1, "Name": "Kaushik", "Designation": ".net Developer", "JoiningDate": "09/23/2013", "Skill": [ { "Id": 1, "SkillName": "C#" }, { "Id": 2, "SkillName": "PHP" }, { "Id": 3, "SkillName": "java" } ] } This is the JSON format I'm working on . Description Of the problem I want to append the file data so I can add more

How to Append a json file without disturbing the formatting

家住魔仙堡 提交于 2020-12-30 06:12:17
问题 I'm working on a file to add/retrieve the data. The data format is JSON . I'm a newbie. I'm using JSON.NET to serialize and deserialize the data. this is the JSON format { "EmpId": 1, "Name": "Kaushik", "Designation": ".net Developer", "JoiningDate": "09/23/2013", "Skill": [ { "Id": 1, "SkillName": "C#" }, { "Id": 2, "SkillName": "PHP" }, { "Id": 3, "SkillName": "java" } ] } This is the JSON format I'm working on . Description Of the problem I want to append the file data so I can add more

How to see if a directory exists or not in Perl?

烂漫一生 提交于 2020-12-29 01:47:26
问题 To see if a file exists before using it, we can use: if (-e "filename.cgi") { #proceed with your code } But how to indentify a directory exists or not? 回答1: Use -d (full list of file tests) if (-d "cgi-bin") { # directory called cgi-bin exists } elsif (-e "cgi-bin") { # cgi-bin exists but is not a directory } else { # nothing called cgi-bin exists } As a note, -e doesn't distinguish between files and directories. To check if something exists and is a plain file, use -f . 来源: https:/

How to see if a directory exists or not in Perl?

北慕城南 提交于 2020-12-29 01:42:27
问题 To see if a file exists before using it, we can use: if (-e "filename.cgi") { #proceed with your code } But how to indentify a directory exists or not? 回答1: Use -d (full list of file tests) if (-d "cgi-bin") { # directory called cgi-bin exists } elsif (-e "cgi-bin") { # cgi-bin exists but is not a directory } else { # nothing called cgi-bin exists } As a note, -e doesn't distinguish between files and directories. To check if something exists and is a plain file, use -f . 来源: https:/