Skip to main content

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.

Filter by
Sorted by
Tagged with
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 '...
Nathan's user avatar
  • 76.8k
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.
Parand's user avatar
  • 105k
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?
Laurie Young's user avatar
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?
duhhunjonn's user avatar
  • 45.3k
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?
Zygimantas's user avatar
  • 34.6k
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?
John Howard's user avatar
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 ...
Adam Halasz's user avatar
  • 58.1k
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 ...
g_inherit's user avatar
  • 19.9k
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?
David542's user avatar
  • 109k
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\\'
Shubham's user avatar
  • 22k
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 ...
Sibi's user avatar
  • 48.3k
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 ...
Ram Rachum's user avatar
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?
qazwsx's user avatar
  • 26.5k
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.
Brad Zeis's user avatar
  • 10.6k
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 ...
Tavousi's user avatar
  • 15.3k
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?
Itzik984's user avatar
  • 16.5k
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?
andersjanmyr's user avatar
  • 11.5k
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.
foobarfuzzbizz's user avatar
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 ...
Gilean's user avatar
  • 14.7k
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.
M.J.'s user avatar
  • 16.5k
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 ...
Scott B's user avatar
  • 39.7k
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)?
Senthil Kumar's user avatar
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 ...
Marcel's user avatar
  • 8,289
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.
Jeff's user avatar
  • 15.6k
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 ...
Jonathan Livni's user avatar
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:\...
Even Mien's user avatar
  • 45.4k
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 ...
Aaron de Windt's user avatar
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 ...
Keith's user avatar
  • 154k
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?
Matt's user avatar
  • 86.9k
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 ...
Gary Willoughby's user avatar
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).
ThomasReggi's user avatar
  • 58.1k
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 ...
nebuch's user avatar
  • 6,825
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 ...
Chase's user avatar
  • 68.6k
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?
Gaurav Agarwal's user avatar
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 ...
SnAzBaZ's user avatar
  • 6,549
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="...
tom's user avatar
  • 5,354
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.
jimmy's user avatar
  • 8,271
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("/")?
Manu's user avatar
  • 29k
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 ...
user680406's user avatar
  • 5,717
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 ...
user avatar
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....
Cristian Diaconescu's user avatar
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.
Željko Filipin's user avatar
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>...
Grofit's user avatar
  • 18.2k
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 ...
Peter Becker's user avatar
  • 8,855
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 ...
user42228's user avatar
  • 4,195
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. ...
Deniz Zoeteman's user avatar
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?
hsz's user avatar
  • 151k
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 ?
Gaetan Dubar's user avatar
  • 4,578
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?
John Assymptoth's user avatar

1
2 3 4 5
402