directory

How do I distinguish a file from a directory in Perl?

旧街凉风 提交于 2019-12-18 12:49:37
问题 I'm trying to traverse through all the subdirectories of the current directory in Perl, and get data from those files. I'm using grep to get a list of all files and folders in the given directory, but I don't know which of the values returned is a folder name and which is a file with no file extention. How can I tell the difference? 回答1: You can use a -d file test operator to check if something is a directory. Here's some of the commonly useful file test operators -e File exists. -z File has

How to get the owner and group of a folder with Python on a Linux machine?

亡梦爱人 提交于 2019-12-18 12:16:12
问题 How can I get the owner and group IDs of a directory using Python under Linux? 回答1: Use os.stat() to get the uid and gid of the file. Then, use pwd.getpwuid() and grp.getgrgid() to get the user and group names respectively. import grp import pwd import os stat_info = os.stat('/path') uid = stat_info.st_uid gid = stat_info.st_gid print uid, gid user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] print user, group 回答2: Since Python 3.4.4, the Path class of pathlib module provides a nice

How to get the owner and group of a folder with Python on a Linux machine?

只愿长相守 提交于 2019-12-18 12:16:03
问题 How can I get the owner and group IDs of a directory using Python under Linux? 回答1: Use os.stat() to get the uid and gid of the file. Then, use pwd.getpwuid() and grp.getgrgid() to get the user and group names respectively. import grp import pwd import os stat_info = os.stat('/path') uid = stat_info.st_uid gid = stat_info.st_gid print uid, gid user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] print user, group 回答2: Since Python 3.4.4, the Path class of pathlib module provides a nice

PHP: How can I grab a single file from a directory without scanning entire directory?

吃可爱长大的小学妹 提交于 2019-12-18 11:57:32
问题 I have a directory with 1.3 Million files that I need to move into a database. I just need to grab a single filename from the directory WITHOUT scanning the whole directory. It does not matter which file I grab as I will delete it when I am done with it and then move on to the next. Is this possible? All the examples I can find seem to scan the whole directory listing into an array. I only need to grab one at a time for processing... not 1.3 Million every time. 回答1: This should do it: <?php

linux 基础命令一

柔情痞子 提交于 2019-12-18 11:19:22
linux 基础命令一 天气已进入十二月份,但是这几天的天气好像有些反常,并未感觉多冷,印象中去年的江南很冷,相比较于北方的干冷,似乎南方的湿冷更胜一筹,读书的地方在北方的一座颇具历史文化的小城,因为从小喜欢历史,当初报考志愿的时候也因为这个原因选择了这座小城,读书在北方待了四年,毕业之后来到江南这座城市工作,说不出孰好孰不好,我喜欢北方的厚重,也喜欢南方的细腻,喜欢北方的历史感,也喜欢南方的现代化,喜欢北方的大锅菜,也喜欢南方的小笼包…,此时,外面下着淅淅沥沥的小雨,似乎冬天和小雨更配,天空很暗,三四点钟的午后像是傍晚,午休醒来,也懒得开灯,原本也不到开灯的时间,最近一段的生活,一直是这样重复循环,没有波澜,也没有惊喜,也许这就是生活的常态。 言归正传。 首先 命令格式:命令名 【选项】 【参数】 选项:调节命令功能。 参数:操作对象,不写就是默认对象。 ls (list)查看目录 : -l :长格式显示文件。 : -h:以高可读方式显示。 : -a:显示所有文件。 cd (change directory) 切换目录 :cd 路径 可以用绝对路径 或者 相对路径 pwd (print working directory) 查看当前目录 mkdir (make directory) 创建目录 : -p 递归创建目录 : mkdir a b c 同时创建多个目录 rmdir

Folder naming convention for gradle build variants

自古美人都是妖i 提交于 2019-12-18 11:01:46
问题 I have been struggling for a while with gradle and build variants. I have these build types defined: debug release And these flavors: free paid How can i define unique resources and assets for a certain build variant ie. FreeDebug? For example I want four different app names depending on build variant, and a different icon for each variant. 回答1: I have been struggling with the same problem. At first I used two branches in my source control, but that was a head ache keeping them in sync.

Java.nio: most concise recursive directory delete

柔情痞子 提交于 2019-12-18 10:54:23
问题 I am currently trying to recursively delete a directory... Strangely enough the shortest piece of code I was able to find is the following construct, employing an ad-hoc inner class and in a visitor pattern ... Path rootPath = Paths.get("data/to-delete"); try { Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { System.out.println("delete file: " + file.toString()); Files.delete(file

PHP get path to every file in folder/subfolder into array? [duplicate]

雨燕双飞 提交于 2019-12-18 10:46:32
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: PHP SPL RecursiveDirectoryIterator RecursiveIteratorIterator retrieving the full tree I am not sure where to start. But I have to get the paths to all files in a folder and all the content of the subfolder in paths too. For example if I had 1 folder that had five folders and each folder had 10 mp3s in it etc... That means my array would have to find 50 paths to these files. Later lets say I added one more folder

How can my Perl script find its module in the same directory?

情到浓时终转凉″ 提交于 2019-12-18 10:32:39
问题 I recently wrote a new Perl script to kill processes based on either process name / user name and extended it using Classes so that I could reuse the process code in other programs. My current layout is - /home/mutew/src/prod/pskill <-- Perl script /home/mutew/src/prod/Process.pm <-- Package to handle process descriptions I added ~/src/prod in my $PATH variable to access the script from anywhere. On running the script from any directory other than its resident directory leads to a "Can't

How to rename git root folder?

◇◆丶佛笑我妖孽 提交于 2019-12-18 10:17:41
问题 I've just started using git in Vista, with my repository under /path/to/project/git repo . I've now found that the space in the folder name is a minor irritation when working in git bash. Can I just rename the folder to /path/to/project/gitrepo ? Is everything within the git config relative, or is there anything that explicitly refers to the parent folder? I've tried just taking a windows copy of the main folder, and run git bash on that, and 'git log' shows the changes I had previously made.