file-io

Can Fortran read bytes directly from a binary file?

杀马特。学长 韩版系。学妹 提交于 2019-12-28 15:51:21
问题 I have a binary file that I would like to read with Fortran. The problem is that it was not written by Fortran, so it doesn't have the record length indicators. So the usual unformatted Fortran read won't work. I had a thought that I could be sneaky and read the file as a formatted file, byte-by-byte (or 4 bytes by 4 bytes, really) into a character array and then convert the contents of the characters into integers and floats via the transfer function or the dreaded equivalence statement. But

How do you get the size of a file in MATLAB?

雨燕双飞 提交于 2019-12-28 12:56:26
问题 What is the best way to figure out the size of a file using MATLAB? The first thought that comes to mind is size(fread(fid)) . 回答1: Please see the dir function as stated above. Please note that the dir function works on files and not on directories only. >> s = dir('c:\try.c') s = name: 'try.c' date: '01-Feb-2008 10:45:43' bytes: 20 isdir: 0 datenum: 7.3344e+005 回答2: You can use the DIR function to get directory information, which includes the sizes of the files in that directory. For example

PHP readfile() causing corrupt file downloads

落爺英雄遲暮 提交于 2019-12-28 12:34:15
问题 I am using php script to provide download from my website after a requisite javascript timer this php script is included which causes the download. But the downloaded file is corrupt no matter whatever I try. Can anyone help me point out where am I going wrong. This is my code <?php include "db.php"; $id = htmlspecialchars($_GET['id']); $error = false; $conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); if(!($conn)) echo "Failed To Connect To The Database!"; else{ if(mysql_select_db(DB_NAME,

Verifying that two files are identical using pure PHP?

∥☆過路亽.° 提交于 2019-12-28 12:31:28
问题 TL;DR: I have an CMS system that stores attachments (opaque files) using SHA-1 of the file contents as the filename. How to verify if uploaded file really matches one in the storage, given that I already know that SHA-1 hash matches for both files? I'd like to have high performance. Long version: When an user uploads a new file to the system, I compute SHA-1 hash of the uploaded file contents and then check if a file with identical hash already exists in the storage backend. PHP puts the

Verifying that two files are identical using pure PHP?

我与影子孤独终老i 提交于 2019-12-28 12:29:08
问题 TL;DR: I have an CMS system that stores attachments (opaque files) using SHA-1 of the file contents as the filename. How to verify if uploaded file really matches one in the storage, given that I already know that SHA-1 hash matches for both files? I'd like to have high performance. Long version: When an user uploads a new file to the system, I compute SHA-1 hash of the uploaded file contents and then check if a file with identical hash already exists in the storage backend. PHP puts the

Check if a file exists with Lua

北战南征 提交于 2019-12-28 11:46:22
问题 How can I check if a file exists using Lua? 回答1: Try function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end but note that this code only tests whether the file can be opened for reading. 回答2: Using plain Lua, the best you can do is see if a file can be opened for read, as per LHF. This is almost always good enough. But if you want more, load the Lua POSIX library and check if posix.stat( path ) returns non- nil . 回答3: I will quote

Are there any Java Frameworks for binary file parsing?

↘锁芯ラ 提交于 2019-12-28 10:45:08
问题 My problem is, that I want to parse binary files of different types with a generic parser which is implemented in JAVA. Maybe describing the file format with a configuration file which is read by the parser or creating Java classes which parse the files according to some sort of parsing rules. I have searched quite a bit on the internet but found almost nothing on this topic. What I have found are just things which deal with compiler-generators (Jay, Cojen, etc.) but I don't think that I can

python watchdog monitoring file for changes

 ̄綄美尐妖づ 提交于 2019-12-28 07:39:27
问题 Folks, I have a need to watch a log file for changes. After looking through stackoverflow questions, I see people recommending 'watchdog'. So i'm trying to test, and am not sure where to add the code for when files change: #!/usr/bin/python import time from watchdog.observers import Observer from watchdog.events import LoggingEventHandler if __name__ == "__main__": event_handler = LoggingEventHandler() observer = Observer() observer.schedule(event_handler, path='.', recursive=False) observer

Change file to read-only mode in Python

☆樱花仙子☆ 提交于 2019-12-28 06:32:28
问题 I am writing a data processing code, in which I create a new file, write processed data in to this file and close. But the file has to be closed in read-only mode, so that it would not be accidentally modified. Can this be done in Python? 回答1: For this you use os.chmod import os from stat import S_IREAD, S_IRGRP, S_IROTH filename = "path/to/file" os.chmod(filename, S_IREAD|S_IRGRP|S_IROTH) Note that this assumes you have appropriate permissions, and that you want more than just the owner to

Change file to read-only mode in Python

时光总嘲笑我的痴心妄想 提交于 2019-12-28 06:32:13
问题 I am writing a data processing code, in which I create a new file, write processed data in to this file and close. But the file has to be closed in read-only mode, so that it would not be accidentally modified. Can this be done in Python? 回答1: For this you use os.chmod import os from stat import S_IREAD, S_IRGRP, S_IROTH filename = "path/to/file" os.chmod(filename, S_IREAD|S_IRGRP|S_IROTH) Note that this assumes you have appropriate permissions, and that you want more than just the owner to