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
1090
votes
23 answers

How do I remove/delete a folder that is not empty?

I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the following command in my attempt: os.remove("/folder_name"). What is the most effective way of removing/deleting a folder/directory that is not…
Amara
  • 13,839
  • 9
  • 32
  • 28
1019
votes
36 answers

How to get full path of a file?

Is there an easy way I can print the full path of file.txt ? file.txt = /nfs/an/disks/jj/home/dir/file.txt The dir> file.txt should print /nfs/an/disks/jj/home/dir/file.txt
Jean
  • 21,665
  • 24
  • 69
  • 119
1016
votes
30 answers

"Cross origin requests are only supported for HTTP." error when loading a local file

I'm trying to load a 3D model, stored locally on my computer, into Three.js with JSONLoader, and that 3D model is in the same directory as the entire website. I'm getting the "Cross origin requests are only supported for HTTP." error, but I don't…
corazza
  • 31,222
  • 37
  • 115
  • 186
970
votes
20 answers

Is there a way to check if a file is in use?

I'm writing a program in C# that needs to repeatedly access 1 image file. Most of the time it works, but if my computer's running fast, it will try to access the file before it's been saved back to the filesystem and throw an error: "File in use by…
Dawsy
  • 10,249
  • 5
  • 20
  • 13
954
votes
26 answers

Writing a list to a file with Python, with newlines

How do I write a list to a file? writelines() doesn't insert newline characters, so I need to do: f.writelines([f"{line}\n" for line in lines])
Josh Arenberg
  • 10,078
  • 5
  • 21
  • 17
918
votes
12 answers

Limit file format when using ?

I'd like to restrict the type of file that can be chosen from the native OS file chooser when the user clicks the Browse button in the element in HTML. I have a feeling it's impossible, but I'd like to know if there is a…
Bojangles
  • 99,427
  • 50
  • 170
  • 208
882
votes
11 answers

"TypeError: a bytes-like object is required, not 'str'" when handling file content in Python 3

I've very recently migrated to Python 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp:…
masroore
  • 9,668
  • 3
  • 23
  • 28
818
votes
29 answers

Convert DOS/Windows line endings to Linux line endings in Vim

If I open files I created in Windows, the lines all end with ^M. How do I delete these characters all at once?
Bert Hekman
  • 8,987
  • 3
  • 21
  • 14
804
votes
24 answers

How do I save a String to a text file using Java?

In Java, I have text from a text field in a String variable called "text". How can I save the contents of the "text" variable to a file?
Justin White
  • 8,273
  • 4
  • 19
  • 9
788
votes
33 answers

How can I get the list of files in a directory using C or C++?

How can I determine the list of files in a directory from inside my C or C++ code? I'm not allowed to execute the ls command and parse the results from within my program.
samoz
  • 56,849
  • 55
  • 141
  • 195
788
votes
27 answers

How to delete the contents of a folder?

How can I delete the contents of a local folder in Python? The current project is for Windows, but I would like to see *nix also.
UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
787
votes
19 answers

How do I call a function from another .py file?

file.py contains a function named function. How do I import it? from file.py import function(a,b) The above gives an error: ImportError: No module named 'file.py'; file is not a package
user2977230
  • 8,897
  • 5
  • 14
  • 9
784
votes
35 answers

How to read all files in a folder from Java?

How to read all the files in a folder through Java? It doesn't matter which API.
M.J.
  • 16,266
  • 28
  • 75
  • 97
776
votes
20 answers

Rename a file in C#

How do I rename a file using C#?
Gold
  • 60,526
  • 100
  • 215
  • 315
743
votes
10 answers

How to upload a file in Django?

What is the minimal example code needed for a "hello world" app using Django 1.3, that enables the user to upload a file?
qliq
  • 11,695
  • 15
  • 54
  • 66