Questions tagged [file]

A block of arbitrary information, or resource for storing information, accessible by the string-based name or path. Files are available to computer programs and are usually based on some kind of persistent storage.

A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished. Computer files can be considered as the modern counterpart of paper documents which traditionally are kept in offices' and libraries' files, and this is the source of the term.

In modern computer architectures, files are organized in a tree structure. On the top, you have a root like C:\ in systems. There are several subfolders (inner nodes) below the root, e.g. Program Files or Users. The computer files, which contain the data, are the leaves of that tree.

On based systems, many types of system information are also represented as files, in filesystems such as sysfs and devfs, even though they don't represent information on a durable storage medium.


References


Related

, , , , ,

81192 questions
730
votes
18 answers

How do I find files that do not contain a given string pattern?

How do I find out the files in the current directory which do not contain the word foo (using grep)?
Senthil Kumar
  • 9,695
  • 8
  • 36
  • 45
723
votes
38 answers

Generate an integer that is not among four billion given ones

I have been given this interview question: Given an input file with four billion integers, provide an algorithm to generate an integer which is not contained in the file. Assume you have 1 GB memory. Follow up with what you would do if you have…
SecureFish
  • 2,391
  • 7
  • 32
  • 43
694
votes
12 answers

How can I split a large text file into smaller files with an equal number of lines?

I've got a large (by number of lines) plain text file that I'd like to split into smaller files, also by number of lines. So if my file has around 2M lines, I'd like to split it up into 10 files that contain 200k lines, or 100 files that contain…
danben
  • 80,905
  • 18
  • 123
  • 145
682
votes
7 answers

Find duplicate lines in a file and count how many time each line was duplicated?

Suppose I have a file similar to the following: 123 123 234 234 123 345 I would like to find how many times '123' was duplicated, how many times '234' was duplicated, etc. So ideally, the output would be like: 123 3 234 2 345 1
user839145
  • 6,883
  • 3
  • 16
  • 10
679
votes
5 answers

Getting file size in Python?

Is there a built-in function for getting the size of a file object in bytes? I see some people do something like this: def getSize(fileobject): fileobject.seek(0,2) # move the cursor to the end of the file size = fileobject.tell() return…
6966488-1
  • 6,823
  • 2
  • 15
  • 3
672
votes
5 answers

Why is “while( !feof(file) )” always wrong?

What is wrong with using feof() to control a read loop? For example: #include #include int main(int argc, char **argv) { char *path = "stdin"; FILE *fp = argc > 1 ? fopen(path=argv[1], "r") : stdin; if( fp == NULL…
William Pursell
  • 204,365
  • 48
  • 270
  • 300
658
votes
14 answers

How to check if a file exists in Go?

Go's standard library does not have a function solely intended to check if a file exists or not (like Python's os.path.exists). What is the idiomatic way to do it?
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
642
votes
10 answers

How do I get the directory from a file's full path?

What is the simplest way to get the directory that a file is in? I'm using this to set a working directory. string filename = @"C:\MyDirectory\MyFile.bat"; In this example, I should get "C:\MyDirectory".
Even Mien
  • 44,393
  • 43
  • 115
  • 119
627
votes
10 answers

logger configuration to log to file and print to stdout

I'm using Python's logging module to log some debug strings to a file which works pretty well. Now in addition, I'd like to use this module to also print the strings out to stdout. How do I do this? In order to log my strings to a file I use…
stdcerr
  • 13,725
  • 25
  • 71
  • 128
621
votes
23 answers

Fastest way to check if a file exists using standard C++/C++11,14,17/C?

I would like to find the fastest way to check if a file exists in standard C++11, 14, 17, or C. I have thousands of files and before doing something on them I need to check if all of them exist. What can I write instead of /* SOMETHING */ in the…
Vincent
  • 57,703
  • 61
  • 205
  • 388
616
votes
35 answers

How can I create an empty file at the command line in Windows?

How can I create an empty file at the DOS/Windows command-line? I tried: copy nul > file.txt But it always displays that a file was copied. Is there another method in the standard cmd? It should be a method that does not require the touch command…
Grendler
  • 6,327
  • 3
  • 16
  • 8
615
votes
3 answers

When should I use File.separator and when File.pathSeparator?

In the File class there are two strings, separator and pathSeparator. What's the difference? When should I use one over the other?
icnhzabot
  • 9,801
  • 5
  • 21
  • 9
605
votes
21 answers

Directory-tree listing in Python

How do I get a list of all files (and directories) in a given directory in Python?
Matt
  • 84,419
  • 25
  • 57
  • 67
590
votes
27 answers

How to sparsely checkout only one single file from a git repository?

How do I checkout just one file from a git repo?
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
578
votes
16 answers

Quickly create a large file on a Linux system

How can I quickly create a large file on a Linux (Red Hat Linux) system? dd will do the job, but reading from /dev/zero and writing to the drive can take a long time when you need a file several hundreds of GBs in size for testing... If you need to…
DrStalker
  • 9,061
  • 17
  • 43
  • 47