file-io

Python get most recent file in a directory with certain extension

假如想象 提交于 2020-01-12 03:27:44
问题 I'm trying to use the newest file in the 'upload' directory with '.log' extension to be processed by Python. I use a Ubuntu web server and file upload is done by a html script. The uploaded file is processed by a Python script and results are written to a MySQL database. I used this answer for my code. import glob newest = max(glob.iglob('upload/*.log'), key=os.path.getctime) print newest f = open(newest,'r') But this is not getting the newest file in the directory, instead it gets the oldest

reading a text file to MATLAB with different formatting

限于喜欢 提交于 2020-01-11 13:21:08
问题 I have a text file, but unfortunately its been poorly formatted, however i want to read the content of the text file into a a matrix, but I don't know how to do that. When try to use fscanf , textscan , textread and the rest it just copies everything into one cell, but i don't want it that way. This how the content looks like: so i want to read only the decimals not the absolute figures. Can someone help me. 1 : 13.27 ; 3 : 20.68 ; 6 : 8.271 ; 7 : 3.308 ; 8 : 8.328 ; 9 : 6.655 ; 10 : 16.58 ;

reading a text file to MATLAB with different formatting

我的未来我决定 提交于 2020-01-11 13:21:05
问题 I have a text file, but unfortunately its been poorly formatted, however i want to read the content of the text file into a a matrix, but I don't know how to do that. When try to use fscanf , textscan , textread and the rest it just copies everything into one cell, but i don't want it that way. This how the content looks like: so i want to read only the decimals not the absolute figures. Can someone help me. 1 : 13.27 ; 3 : 20.68 ; 6 : 8.271 ; 7 : 3.308 ; 8 : 8.328 ; 9 : 6.655 ; 10 : 16.58 ;

Java - Load file, replace string, save

非 Y 不嫁゛ 提交于 2020-01-11 12:39:49
问题 I have a program that loads lines from a user file, then selects the last part of the String (which would be an int) Here's the style it's saved in: nameOfValue = 0 nameOfValue2 = 0 and so on. I have selected the value for sure - I debugged it by printing. I just can't seem to save it back in. if(nameOfValue.equals(type)) { System.out.println(nameOfValue+" equals "+type); value.replace(value, Integer.toString(Integer.parseInt(value)+1)); } How would I resave it? I've tried bufferedwriter but

Save ImageView to Android Emulator Gallery

三世轮回 提交于 2020-01-11 12:34:07
问题 I'd like to Save an Image to the Android Gallery, here's my current code: image.setDrawingCacheEnabled(true); image.buildDrawingCache(true); Bitmap b = image.getDrawingCache(); if(!new File("/"+Environment.DIRECTORY_PICTURES).exists()) Log.e("Error","/"+Environment.DIRECTORY_PICTURES+" Dont exist"); File file = new File(Environment.DIRECTORY_PICTURES+"/myImage.jpg"); file.createNewFile(); FileOutputStream ostream = new FileOutputStream(file); b.compress(CompressFormat.JPEG, 80, ostream);

Python error os.walk IOError

两盒软妹~` 提交于 2020-01-11 11:52:16
问题 I tried to track the file with server in the filename and i can print all the file in directory with server** but when I try to read the file it gives me error" saying: Traceback (most recent call last): File "view_log_packetloss.sh", line 27, in <module> with open(filename,'rb') as files: IOError: [Errno 2] No such file or directory: 'pcoip_server_2014_05_19_00000560.txt' I have seen similar question being asked but I could not fix mine, some error were fixed using chdir to change the

Using fgets to read strings from file in C

隐身守侯 提交于 2020-01-11 11:07:32
问题 I am trying to read strings from a file that has each string on a new line but I think it reads a newline character once instead of a string and I don't know why. If I'm going about reading strings the wrong way please correct me. i=0; F1 = fopen("alg.txt", "r"); F2 = fopen("tul.txt", "w"); if(!feof(F1)) { do{ //start scanning file fgets(inimene[i].Enimi, 20, F1); fgets(inimene[i].Pnimi, 20, F1); fgets(inimene[i].Kood, 12, F1); printf("i=%d\nEnimi=%s\nPnimi=%s\nKaad=%s",i,inimene[i].Enimi

Using fgets to read strings from file in C

守給你的承諾、 提交于 2020-01-11 11:07:11
问题 I am trying to read strings from a file that has each string on a new line but I think it reads a newline character once instead of a string and I don't know why. If I'm going about reading strings the wrong way please correct me. i=0; F1 = fopen("alg.txt", "r"); F2 = fopen("tul.txt", "w"); if(!feof(F1)) { do{ //start scanning file fgets(inimene[i].Enimi, 20, F1); fgets(inimene[i].Pnimi, 20, F1); fgets(inimene[i].Kood, 12, F1); printf("i=%d\nEnimi=%s\nPnimi=%s\nKaad=%s",i,inimene[i].Enimi

Randomly select file in PHP

女生的网名这么多〃 提交于 2020-01-11 10:33:31
问题 I'd like to use the 'include' keyword in php to randomly select a file from a folder and output the contents. How would I do this? Thanks. 回答1: Assuming you know the folder where the files are and that the files are PHP files: $phpFiles = glob('/path/to/files/*.php'); if (empty($phpFiles) === false) { $randomFile = $phpFiles[array_rand($phpFiles)]; include($randomFile); } 回答2: glob() would read filenames into array. and then you can shuffle this array and pick a random item. 回答3: use glob to

Open any file from asp.net

倖福魔咒の 提交于 2020-01-11 09:37:09
问题 How can I open any file, specified by a path, in ASP.NET programatically? I tried the snippet below but it reads the contents of the file instead of opening the file: string fileName = @"C:\deneme.txt"; StreamReader sr = File.OpenText(fileName); while (sr.Peek() != -1) { Response.Write(sr.ReadLine() + "<br>"); } sr.Close(); I also tried the File.Open method. 回答1: You can Response.Redirect to file if you're just opeining it or if file is being downloaded you can use the folling code; public