I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?
Here's my code:
import os
import shutil
dir = '/somedir...
I am trying to output the results of my reducer to multiple files. The data results are all contained in one file, and the rest of the results are split based on a category in their respected files. I know with 0.18 that you can do this with MultipleOutputs and it has not been removed. However, I am trying to make my application 0.20+ co...
C++ is not my preferred language.
I have a file that contains this:
e 225,370 35,75
I want to separate e, 225, 370, 35 and 75 from each other into a char and ints but I'm having trouble. I tried doing everything I found online and in my C++ book and still it's not working out. Please help.
I would have an easier time doing this in...
var t1 = from line in File.ReadAllLines(@"alkahf.txt")
let item = line.Split(new string[] {". "}, StringSplitOptions.RemoveEmptyEntries)
let verse = line.Split(new string[] { "\n. " }, StringSplitOptions.RemoveEmptyEntries)
select new
{
...
I am trying to remove a large number of files from a location (by large I mean over 100000), whereby the action is initated from a web page. Obviously I could just use
string[] files = System.IO.Directory.GetFiles("path with files to delete");
foreach (var file in files) {
IO.File.Delete(file);
}
Directory.GetFiles
http://msdn.mi...
Okay I;m really new to VB.NET and desktop application development. Simplified this is what is happening in my application:
Dim Files() As New List(Of IO.FileInfo)
Files.Add( (New IO.FileInfo("C:\img1.jpg")) )
Files.Add( (New IO.FileInfo("C:\img2.jpg")) )
'Picture is a Windows.Forms.PictureBox in my WinForm '
Picture.Image = New System....
Hi,
I'm a programming student in my second OOP class, my first class was taught in C# and this class is taught in C++. To get our feet wet in C++, our professor has asked us to write a rather large program with File I/O. The problem is, I have a small part of my program that is not working, at least, not for me. The project requires tha...
code:
file.write 'objectclass: groupOfUniqueNames\n'
Oddly enough, the \n is actually being printed... What is wrong here?
...
We are wanting to replace our current update system for the POS software at our stores. Currently, we have a folder on our webserver that hosts a script that our registers call every 30 minutes or so. They pass in their current version number, and the server returns an XML response containing any files that need to be updated, hash, an...
I have a python script that is constantly grabbing data from Twitter and writing the messages to a file. The question that I have is every hour, I want my program to write the current time to the file. Below is my script. Currently, it gets into the timestamp function and just keeps printing out the time every 10 seconds.
#! /usr/bin/en...
I'm trying to figure out how to continuously read a file and once there is a new line added, output the line. I'm doing this using a sleep thread however it just seems to blow through the whole file and exit the program.
Any suggestions what I'm doing wrong?
Here is my code:
import java.io.*;
import java.lang.*;
import java.util....
I have a C++/Obj-C background and I am just discovering Python (been writing it for about an hour).
I am writing a script to recursively read the contents of text files in a folder structure.
The problem I have is the code I have written will only work for one folder deep. I can see why in the code (see #hardcoded path), I just don't kn...
I have a code which at first search for some files that have the "java" extension and then I want to copy the content of one file to these files which has the "java" extension but I don't know that why this code doesn't work?
public static void main(String[] args) {
if (args.length > 0) {
FileInputStream in = null;
...
Hi, I'm programming in Windows right now, but portable code would be welcomed too.
What I'm using right now is fwrite(4), but this function needs a maximum number of elements to be written to the file. I can use strlen(1) here but I'd like to know if there is any better way to do this.
...
I'm writing a program which reads text from a file, and determines the number of sentences, words, and syllables of that file. The trick is, it must only read one character a time, and work with that. Which means it can't just store the whole file in an array.
So, with that in mind, heres how my program works:
while(character != EOF)
{...
In my jnlp app I need to know if a user property file exists, if it does, load it, my code looks like this :
File_Contents=File_Open_Service.openFileDialog(".",new String[]{".txt"});
String Text=readFromFile(File_Contents);
InputStreamReader in=new InputStreamReader(File_Contents.getInputStream());
Application_Props.load(in);
Users d...
I am writing a Java app that uploads image and video files to a server side script. So far I've got the image upload happening using HTTPURLConnection/DataOutputstream and it seems that I might be able re-use a good deal of the code I've written to also upload the video. My question is, where the following snippet declares that the Conte...
A simple question:
I need to add some logging to my program.
If two processes use "fwrite" on the same file but not the same file descriptor will the written log messages be atomic or mixed. Is there a length limit?
Is it defined ANSI-C behaviour or implementation defined?
If the later what is on MacOSX, Linux and Windows MSVC?
...
I need to delete a file. Occasionally, the file may be locked, in this case I'd like to unlock it and delete it anyway.
I've come across two possibilities in the research so far.
System.IO.FileStream.Unlock
and
//unlock file
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool UnlockFile(IntPtr handle, int of...
As far I know, the two most common methods of reading character-based data from a file in Java is using Scanner or BufferedReader. I also know that the BufferedReader read files efficiently by using a buffer to avoid physical disk operations. My questions are:
Does Scanner performs as well as BufferedReader?
Why would you choose Scann...