Questions tagged [file-handling]

file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files

2915 questions
5
votes
2 answers

array elements gets deleted when looping files

I have a problem with looping through file names, my input array elements gets deleted. CODE: use Data::Dumper; use warnings; use strict; my @files = ("file1", "file2", "file3"); print Dumper(\@files); for (@files) { my $filename = $_ .…
gmezos
  • 53
  • 3
5
votes
2 answers

Zip a directory target

I'm using this basic script in Python 2.6 to zip a directory : def zipdir(path, ziph): import os, zipfile for(dir, _, files) in os.walk(path): for file in files: ziph.write(os.path.join(dir, file)) ziph =…
GrandGTO
  • 333
  • 3
  • 14
5
votes
2 answers

Perl file handles - overwrite existing data instead of appending/deleting

cat -E test1.txt output: car$ $ $ I want just change "car" with "bike" and remove new/empty lines. This is working as expected: #!/usr/bin/perl -w open(FILE1,"<","./test1.txt"); @araj=; close(FILE1); open(FILE2,">","./test1.txt"); map…
rdbeni0
  • 152
  • 3
  • 8
5
votes
2 answers

What happens to open files which are not properly closed?

What happens if I do not close a file after writing to it? Let us assume we got an too many open files error and due to that the program crashes. Does the OS handle that for me? And if this damages the not-closed files, how do I notice that they…
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
5
votes
3 answers

flush() java file handling

What is the exact use of flush()? What is the difference between stream and buffer? Why do we need buffer?
Sumithra
  • 6,587
  • 19
  • 51
  • 50
5
votes
1 answer

Check if file content has been actually written to disk - not being queued in disk controller's buffer

I wrote a program that compacts two small files into a single-bigger file. I first read data from input files, merge data, and write output to a temp file. Once this completes I rename the temp file to the desired file name (located in the same…
duong_dajgja
  • 4,196
  • 1
  • 38
  • 65
5
votes
2 answers

Detect endianness of binary file data

Recently I was (again) reading about 'endian'ness. I know how to identify the endianness of host, as there are lots of post on SO, and also I have seen this, which I think is pretty good resource. However, one thing I like to know is to how to…
Sayan Pal
  • 4,768
  • 5
  • 43
  • 82
5
votes
1 answer

System calls in Linux that can be used to delete files

What are the system calls that can be used to delete a file on Linux? I am not referring to just the system calls used by the libc-wrapper(which in-turn are used by command line tools). Other than unlink and unlinkat what are the system calls that…
user277465
5
votes
4 answers

How to change multiple filenames in a directory using Python

I am learning Python and I have been tasked with: adding "file_" to the beginning of each name in a directory changing the extension (directory contains 4 different types currently: .py, .TEXT, .rtf, .text) I have many files, all with different…
Dana Scott
  • 177
  • 1
  • 6
5
votes
1 answer

Python:How to change the position in the file from current file position?

I want to change the file position from the current file position to another position.Suppose my current file position is 13 and I want to change this file position to the 18. I use the seek() method as follow but it shows some error. Code:- fileobj…
Aditya
  • 1,214
  • 7
  • 19
  • 29
5
votes
1 answer

About PHP's fseek() method, what exactly offset (position) is?

Perhaps its my english but the explanation in the PHP Manual (quoted bellow) doesn't answer my question quite clearly. To move to a position before the end-of-file, you need to pass a negative value in offset and set whence to SEEK_END. I have a…
Ali
  • 2,993
  • 3
  • 19
  • 42
5
votes
2 answers

Windows: Delete EXE after execution

I am working on an application in C# which does the following things: Write an EXE to disk Execute the EXE through Process.Start() I am now trying to ensure that the EXE will be deleted once it is closed. The easiest way to do so is to set the…
0x90
  • 6,079
  • 2
  • 36
  • 55
5
votes
1 answer

Tring to read a text file with emoji and print it

Input -> Output-> ≡ƒÿé≡ƒÿé I simply want to maintain the original state of the emoji. All i am doing is this #include #include int main() { char ch; FILE *fp; fp = fopen("test.txt","r"); while( ( ch =…
karx
  • 557
  • 2
  • 6
  • 16
5
votes
2 answers

Python 3 - Deleting pictures from a folder that are under 1920x1080

I am using a subreddit scraper to download images from wallpaper subreddits. The problem I am having is that some images have a small resolution causing them to look awful when used as wallpapers. I have found that the minimum resolution needed for…
user2885647
  • 855
  • 2
  • 9
  • 10
5
votes
6 answers

Why am i getting this warning in "if (fd=fopen(fileName,"r") == NULL)"?

FILE *fd; if (fd=fopen(fileName,"r") == NULL) { printf("File failed to open"); exit(1); } This is a code snippet. When I compile it with gcc, i get the following warning:- warning: assignment makes pointer from integer without a…
shadyabhi
  • 16,675
  • 26
  • 80
  • 131