file-io

How to remove newlines from a text file with batch or PowerShell

左心房为你撑大大i 提交于 2020-01-24 07:49:14
问题 Essentially, I want to read from file.txt with contents apple banana carrot and write to newfile.txt so that it will have contents apple banana carrot I need to do this on a Windows computer on which I do not have install permissions. I tried set row= for /f %%x in (file.txt) do set row=%row% %%x echo row > newfile.txt and I tried using PowerShell statements (I cannot run PowerShell scripts) instead of the CMD-style for loop. powershell -Command "(Gc file.txt) | Foreach-Object -Process {set

Create file header (metadata of file) in C

我的未来我决定 提交于 2020-01-24 05:19:27
问题 File header contains the all data about the file — metadata. I want to create a blank file with metadata, then I want to add other file content to this blank file and need to change (modify) metadata. Is there any library in C for creating file header? How to read/write file header in C? metadata = { file_name; file_size; file_type; file_name_size; total_files; } 回答1: There are probably a number of libraries that handle specific file formats, such as the variations on tar , but not one that

Medium-Trust File I/O permission

帅比萌擦擦* 提交于 2020-01-24 04:09:30
问题 According to this MSDN article about medium trust, under medium-trust: FileIOPermission is restricted. This means you can only access files in your application's virtual directory hierarchy. Your application is granted Read, Write, Append, and PathDiscovery permissions for your application's virtual directory hierarchy. However, for my current hosting provider runs applications under medium-trust and when I try to read/write a file in the application's root folder, I get a access to path

Replace certain element in only first line of the text file

坚强是说给别人听的谎言 提交于 2020-01-24 00:14:06
问题 Thank you for your interest on my maybe silly question. I have a text file and would like to replace certain elements which is "NaN". I usually have used file.replace function for change NaNs with a certain number through entire text file. Now, I would like to replace NaNs with a certain number in only first line of text file, not whole text. Would you give me a hint for this problem? 回答1: You can only read the whole file, call .replace() for the first line and write it to the new file. with

python file I/O with binary data

你。 提交于 2020-01-23 19:44:44
问题 I'm extracting jpeg type bits from mp3 data actually it will be album arts. I thought about using library called mutagen, but I'd like to try with bits for some practice purpose. import os import sys import re f = open(sys.argv[1], "rb") #sys.argv[1] gets mp3 file name ex) test1.mp3 saver = "" for value in f: for i in value: hexval = hex(ord(i))[2:] if (ord(i) == 0): saver += "00" #to match with hex form else: saver += hexval header = "ffd8" tail = "ffd9" this part of code is to get mp3 as

python file I/O with binary data

自闭症网瘾萝莉.ら 提交于 2020-01-23 19:42:09
问题 I'm extracting jpeg type bits from mp3 data actually it will be album arts. I thought about using library called mutagen, but I'd like to try with bits for some practice purpose. import os import sys import re f = open(sys.argv[1], "rb") #sys.argv[1] gets mp3 file name ex) test1.mp3 saver = "" for value in f: for i in value: hexval = hex(ord(i))[2:] if (ord(i) == 0): saver += "00" #to match with hex form else: saver += hexval header = "ffd8" tail = "ffd9" this part of code is to get mp3 as

Recursively copying files with progress

时光怂恿深爱的人放手 提交于 2020-01-23 18:01:05
问题 I've seen questions asked here before about Python and copying files, but I have a different scenario to deal with. I'm almost done with a Linux distro installer I've been working on, and now all it needs to do is copy the files over to the destination partition. As most distro installers have a progress bar, I was hoping to add one too. Right now, I'm using PyQt4 and my code looks like this: self.status('Counting files...') self.count = int(check_output(['-c', 'find /opt/linux/work/root

Extract Date and Currency value(separated by comma) from file

雨燕双飞 提交于 2020-01-23 17:21:26
问题 Objective: Extract String data, Currency value , [type of currency] and date. Content of file: [["1234567890","Your previous month subscription point is <RS|$|QR|#> 5,200.33.Your current month month subscription point is <RS|$|QR|#> 1,15,200.33, Last Year total point earned <RS|$|QR|#> 5589965.26 and point lost in game is <RS|$|QR|#> 11520 your this year subscription will expire on 19-04-2013. 9. Back"],["1234567890","Your previous month subscription point is <RS|$|QR|#> 5,200.33.Your current

How to make this sorting program in C much faster for the large input sets

一世执手 提交于 2020-01-23 14:57:27
问题 This sort code fails for very large input file data because it takes too long for it to finish. rewind(ptr); j=0; while(( fread(&temp,sizeof(temp),1,ptr)==1) &&( j!=lines-1)) //read object by object { i=j+1; while(fread(&temp1,sizeof(temp),1,ptr)==1) //read next object , to compare previous object with next object { if(temp.key > temp1.key) //compare key value of object { temp2=temp; //if you don't want to change records and just want to change keys use three statements temp2.key =temp.key;

.click() on <input type=“file” /> does not work in Firefox 3.6 - Any workarounds?

独自空忆成欢 提交于 2020-01-23 13:30:11
问题 Here is a little example: (live demo here) HTML: <input id="file" type="file" /> Javascript: $(function() { $("#file").click(); }); In Firefox 3.6.6 nothing happens, while in IE7 the "Choose File" dialog box is opened. Any ideas how to open the "Choose File" dialog box in Firefox without clicking on the Browse button ? 回答1: The file-dialog breaks out of the sandbox your javascript code runs in (access to HDD). Good/secure browsers (= not IE7) should prevent that this dialog is opened via a