Questions tagged [directory]
A directory or folder is a container within a digital file system, in which groups of computer files and other directories can be kept and organized.
directory
20,052
questions
7535
votes
56
answers
11.2m
views
Find all files containing a specific text (string) on Linux?
How do I find all files containing a specific string of text within their file contents?
The following doesn't work. It seems to display every single file in the system.
find / -type f -exec grep -H '...
6278
votes
77
answers
2.6m
views
How do I get the directory where a Bash script is located from within the script itself?
How do I get the path of the directory in which a Bash script is located, inside that script?
I want to use a Bash script as a launcher for another application. I want to change the working directory ...
5698
votes
27
answers
3.8m
views
How do I create a directory, and any missing parent directories?
How do I create a directory at a given path, and also create any missing parent directories along that path? For example, the Bash command mkdir -p /path/to/nested/directory does this.
5380
votes
37
answers
1.6m
views
How do I add an empty directory to a Git repository?
How do I add an empty directory (that contains no files) to a Git repository?
3465
votes
21
answers
8.4m
views
How do I list all files of a directory?
How can I list all files of a directory in Python and add them to a list?
3424
votes
18
answers
3.7m
views
How can I delete a file or folder in Python?
How can I delete a file or folder in Python?
3026
votes
13
answers
5.0m
views
Find the current directory and file's directory [duplicate]
How do I determine:
the current directory (where I was in the shell when I ran the Python script), and
where the Python file I am executing is?
2177
votes
19
answers
5.2m
views
How do I change permissions for a folder and its subfolders/files? [closed]
How do I change the permissions of a folder and all its subfolders and files?
This only applies to the /opt/lampp/htdocs folder, not its contents:
chmod 775 /opt/lampp/htdocs
How do I set chmod 755 ...
1985
votes
47
answers
1.7m
views
Download a single folder or directory from a GitHub repository
How can I download only a specific folder or directory from a remote Git repository hosted on GitHub?
Say the example GitHub repository lives here:
[email protected]:foobar/Test.git
Its directory ...
1614
votes
15
answers
1.6m
views
How do I check if a directory exists in Python?
How do I check if a directory exists in Python?
1475
votes
12
answers
2.6m
views
How do I get the full path of the current file's directory? [duplicate]
How do I get the current file's directory path?
I tried:
>>> os.path.abspath(__file__)
'C:\\python27\\test.py'
But I want:
'C:\\python27\\'
1309
votes
29
answers
1.2m
views
Listing only directories using ls in Bash? [closed]
This command lists directories in the current path:
ls -d */
What exactly does the pattern */ do?
And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents) for ...
1116
votes
33
answers
1.5m
views
Importing modules from parent folder
I am running Python 2.5.
This is my folder tree:
ptdraft/
nib.py
simulations/
life/
life.py
(I also have __init__.py in each folder, omitted here for readability)
How do I import the ...
1041
votes
14
answers
700k
views
In a Git repository, how to properly rename a directory?
I think it should work to copy the directory to be renamed to a new directory with desired name, and delete the old directory, and git add, git commit and push everything. But is this the best way?
978
votes
35
answers
1.6m
views
Getting a list of all subdirectories in the current directory
Is there a way to return a list of all the subdirectories in the current directory in Python?
I know you can do this with files, but I need to get the list of directories instead.
970
votes
18
answers
1.2m
views
If a folder does not exist, create it
I use a FileUploader control in my application. I want to save a file to a specified folder. If this folder does not exist, I want to first create it, and then save my file to this folder. If the ...
925
votes
11
answers
1.3m
views
How can I iterate over files in a given directory?
I need to iterate through all .asm files inside a given directory and do some actions on them.
How can this be done in a efficient way?
818
votes
43
answers
738k
views
How can I rename a project folder from within Visual Studio?
My current solution for renaming the project folder is:
Remove the project from the solution.
Rename the folder outside Visual Studio.
Re-add the project to the solution.
Is there a better way?
813
votes
33
answers
1.3m
views
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.
792
votes
22
answers
622k
views
How do I ignore a directory with SVN?
I just started using SVN, and I have a cache directory that I don't need under source control. How can I ignore the whole directory/folder with SVN?
I am using Versions and TextMate on OS X and ...
791
votes
35
answers
1.4m
views
How can I read all files in a folder from Java?
How can I read all the files in a folder through Java? It doesn't matter which API.
767
votes
21
answers
885k
views
Create a folder if it doesn't already exist
I've run into a few cases with WordPress installs with Bluehost where I've encountered errors with my WordPress theme because the uploads folder wp-content/uploads was not present.
Apparently the ...
766
votes
18
answers
429k
views
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)?
745
votes
14
answers
828k
views
How can I Git ignore subfolders / subdirectories?
I have a lot of projects in my .NET solution. I would like to exclude all "bin/Debug" and "bin/Release" folders (and their contents), but still include the "bin" folder ...
701
votes
20
answers
761k
views
What characters are forbidden in Windows and Linux directory names?
I know that / is illegal in Linux, and * " / \ < > : | ? are illegal in Windows.
What else am I missing? I need a comprehensive guide that also accounts for double-byte characters.
689
votes
12
answers
728k
views
How can I find script's directory? [duplicate]
Consider the following Python code:
import os
print os.getcwd()
I use os.getcwd() to get the script file's directory location. When I run the script from the command line it gives me the correct ...
663
votes
10
answers
774k
views
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:\...
650
votes
9
answers
871k
views
What is the current directory in a batch file?
I want to create a few batch files to automate a program.
My question is when I create the batch file, what is the current directory?
Is it the directory where the file is located or is it the same ...
630
votes
29
answers
505k
views
Copy the entire contents of a directory in C#
I want to copy the entire contents of a directory from one location to another in C#.
There doesn't appear to be a way to do this using System.IO classes without lots of recursion.
There is a method ...
611
votes
21
answers
714k
views
Directory-tree listing in Python
How do I get a list of all files (and directories) in a given directory in Python?
610
votes
30
answers
621k
views
How to remove illegal characters from path and filenames?
I need a robust and simple way to remove illegal path and file characters from a simple string. I've used the below code but it doesn't seem to do anything, what am I missing?
using System;
using ...
587
votes
9
answers
422k
views
Node.js check if path is file or directory
I can't seem to get any search results that explain how to do this.
All I want to do is be able to know if a given path is a file or a directory (folder).
544
votes
14
answers
1.0m
views
Command prompt won't change directory to another drive
I'm trying to compile some java (learning java currently), and to do so I need to change command-prompt's directory.
C:\...\Admin> cd D:\Docs\Java
C:\...\Admin> cd
C:\...\Admin
It doesn't ...
525
votes
11
answers
418k
views
Folder management with r : Check existence of directory and create it if it doesn't exist
I often find myself writing R scripts that generate a lot of output. I find it cleaner to put this output into its own directory(s). What I've written below will check for the existence of a directory ...
508
votes
26
answers
670k
views
How to create a directory using Ansible
How do you create a directory www at /srv on a Debian-based system using an Ansible playbook?
499
votes
23
answers
394k
views
Better way to check if a Path is a File or a Directory?
I am processing a TreeView of directories and files. A user can select either a file or a directory and then do something with it. This requires me to have a method which performs different actions ...
496
votes
8
answers
488k
views
Check folder size in Bash
I'm trying to write a script that will calculate a directory size and if the size is less than 10GB, and greater then 2GB do some action. Where do I need to mention my folder name?
# 10GB
SIZE="...
486
votes
16
answers
807k
views
How to create a directory in Java?
How do I create Directory/folder?
Once I have tested System.getProperty("user.home");
I have to create a directory (directory name "new folder" ) if and only if new folder does not exist.
475
votes
4
answers
522k
views
Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?
Can anyone explain the difference between Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\") and Server.MapPath("/")?
459
votes
3
answers
1.0m
views
Getting the filenames of all files in a folder [duplicate]
I need to create a list with all names of the files in a folder.
For example, if I have:
000.jpg
012.jpg
013.jpg
I want to store them in a ArrayList with [000,012,013] as values.
What's the best ...
439
votes
4
answers
742k
views
How to remove files and directories quickly via terminal (bash shell) [closed]
From a terminal window:
When I use the rm command it can only remove files.
When I use the rmdir command it only removes empty folders.
If I have a directory nested with files and folders within ...
439
votes
2
answers
389k
views
How to get a path to the desktop for current user in C#?
How do I get a path to the desktop for current user in C#?
The only thing I could find was the VB.NET-only class SpecialDirectories, which has this property:
My.Computer.FileSystem....
438
votes
19
answers
330k
views
Get names of all files from a folder with Ruby
I want to get all file names from a folder using Ruby.
426
votes
21
answers
316k
views
Get all directories within directory nodejs
I was hoping this would be a simple thing, but I cannot find anything out there to do so.
I just want to get all folders/directories within a given folder/directory.
So for example:
<MyFolder>...
415
votes
18
answers
476k
views
How to create a temporary directory/folder in Java?
Is there a standard and reliable way of creating a temporary directory inside a Java application? There's an entry in Java's issue database, which has a bit of code in the comments, but I wonder if ...
415
votes
10
answers
974k
views
How to check permissions of a specific directory?
I know that using ls -l "directory/directory/filename" tells me the permissions of a file. How do I do the same on a directory?
I could obviously use ls -l on the directory higher in the hierarchy ...
407
votes
16
answers
1.3m
views
How to delete files/subfolders in a specific directory at the command prompt in Windows
Say, there is a variable called %pathtofolder%, as it makes it clear it is a full path of a folder.
I want to delete every single file and subfolder in this directory, but not the directory itself.
...
398
votes
17
answers
558k
views
How to quietly remove a directory with content in PowerShell
Using PowerShell, is it possible to remove some directory that contains files without prompting to confirm action?
385
votes
13
answers
209k
views
Best way to require all files from a directory in ruby?
What's the best way to require all files from a directory in ruby ?
374
votes
5
answers
256k
views
What does "opt" mean (as in the "opt" directory)? Is it an abbreviation? [closed]
What does "opt" mean (as in the "opt" directory)? I commonly see this directory in Unix systems with development tools inside.
Is it an abbreviation?