directory

Most efficient/fastest way to get a single file from a directory

三世轮回 提交于 2020-01-05 10:18:24
问题 What is the most efficient and fastest way to get a single file from a directory using Python? More details on my specific problem: I have a directory containing a lot of pregenerated files, and I just want to pick a random one. Since I know that there's no really efficient way of picking a random file from a directory other than listing all the files first, my files are generated with an already random name, thus they are already randomly sorted, and I just need to pick the first file from

Python: Parsing and grouping filenames in directory

十年热恋 提交于 2020-01-05 09:09:32
问题 I'm pretty new to python, but I have lots of experience with MATLAB & C. What I need to do it parse the filenames of files in a particular directory, separate them into groups according to the fields within the file names, and perform operations within these groups. Specifically, the filenames are: PROJECT-x-SUBJECT-x-SESSION-x-TYPE.extension where that '-x-' has been purposely inserted as the field divider. I need to do operations on every group of files that shares the same PROJECT-x

Python: Parsing and grouping filenames in directory

谁说胖子不能爱 提交于 2020-01-05 09:08:48
问题 I'm pretty new to python, but I have lots of experience with MATLAB & C. What I need to do it parse the filenames of files in a particular directory, separate them into groups according to the fields within the file names, and perform operations within these groups. Specifically, the filenames are: PROJECT-x-SUBJECT-x-SESSION-x-TYPE.extension where that '-x-' has been purposely inserted as the field divider. I need to do operations on every group of files that shares the same PROJECT-x

Setting up PostgreSQL, could not connect to database postgres

萝らか妹 提交于 2020-01-05 09:07:22
问题 I will create a django app on Debian 7 with postgreSQL 9.2. I created a droplet in digital ocean. I updated and upgraded the system. I used the following command sudo aptitude install postgresql postgresql-contrib to install postgresql. When I changed user to postgres and I wanted to create a new db user with createuser -P I filled all the fields it wanted but it came up with this error: createuser: could not connect to database postgres: could not connect to server: No such file or directory

How to write a htaccess file to wildcard folder to subdomain

半腔热情 提交于 2020-01-05 07:42:30
问题 I'm trying to redirect all my folders (using a wildcard) to their subdomain. For example: www.mywebsite.com/folder1 to folder1.mywebsite.com/ www.mywebsite.com/folder2 to folder2.mywebsite.com/ www.mywebsite.com/folder3 to folder3.mywebsite.com/ Now without writing a rule for each one of them, is there a way to redirect them all to their respective subdomain? I tried: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$ RewriteRule

How to write a htaccess file to wildcard folder to subdomain

半世苍凉 提交于 2020-01-05 07:42:26
问题 I'm trying to redirect all my folders (using a wildcard) to their subdomain. For example: www.mywebsite.com/folder1 to folder1.mywebsite.com/ www.mywebsite.com/folder2 to folder2.mywebsite.com/ www.mywebsite.com/folder3 to folder3.mywebsite.com/ Now without writing a rule for each one of them, is there a way to redirect them all to their respective subdomain? I tried: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$ RewriteRule

Copy files from source directory to target directory and exclude specific file types from specified directories

元气小坏坏 提交于 2020-01-05 07:39:24
问题 I have created a simple Powershell script to copy files during a deployment from a target directory to a source directory and I would like to exclude a list of files. The caveat however is that I would like the ability to exclude files only from a sub directory if specified. This is the snippet I'm using to perform the copy and exclude a list of files: $SourceDirectory = "C:\Source" $DestinationDirectory = "C:\Destination" $Exclude = @("*.txt*", "*.xml*") Get-ChildItem $SourceDirectory

Copy files from source directory to target directory and exclude specific file types from specified directories

前提是你 提交于 2020-01-05 07:39:11
问题 I have created a simple Powershell script to copy files during a deployment from a target directory to a source directory and I would like to exclude a list of files. The caveat however is that I would like the ability to exclude files only from a sub directory if specified. This is the snippet I'm using to perform the copy and exclude a list of files: $SourceDirectory = "C:\Source" $DestinationDirectory = "C:\Destination" $Exclude = @("*.txt*", "*.xml*") Get-ChildItem $SourceDirectory

makedirs error: can GAE Python create new directories (folders) or not?

烈酒焚心 提交于 2020-01-05 06:55:34
问题 I have seen a number of questions relating to writing files & creating new directories using Python and GAE, but a number of them conclude (not only on SO) by saying that Python cannot write files or create new directories. Yet these commands exist and plenty of other people seem to be writing files and opening directories no problem. I'm trying to write to .txt files and create folders and getting the following errors: Case #1: with open("aardvark.txt", "a") as myfile: myfile.write("i can't

PHP Sort Files In Directory by Type

限于喜欢 提交于 2020-01-05 02:26:14
问题 I wrote the following PHP code to display files in a directory. It uses JQuery to expand folders. Everything works fine but right now it displays all files in alphabetical order mixing file types. I'd like to keep the alphabetical order but display folders and files separately. How can I sort the displayed files so Folders are displayed on top and other files are displayed bellow. In other words, how do I sort the files by file type? Thank you very much! <?php $path = ROOT_PATH; $dir_handle =