directory

How can I create directory tree in C?

时光毁灭记忆、已成空白 提交于 2020-06-28 09:15:00
问题 I want an easy way to create multiple directories in C. For example I want to create directory in: /a/b/c but if the directories are not there I want them to be created automagically. How can I do this ? 回答1: Here is a small C program to create the directory tree a/b/c in the current directory: #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <errno.h> int create_dir(char *name) { int rc; rc = mkdir(name, S_IRWXU); if (rc != 0 && errno != EEXIST) { perror("mkdir"); exit(1

Python: List Directories and Sizes

痞子三分冷 提交于 2020-06-28 04:24:09
问题 I'm trying to write some Python code that will traverse each directory in the current working directory and report the total size (in bytes) under each directory, regardless of how deep each directory itself goes. This is just for a learning project, I realize there are already other ways to get this information through the shell. Here's some code I have so far: # get name of current working directory start_directory = os.getcwd() # create dictionary to hold the size of each folder in # the

Reading Japanese filenames in windows, using Python and glob not working

孤街醉人 提交于 2020-06-25 07:05:27
问题 I just setup PortablePython on my system, so I can run python scripts from PHP and I got some very basic code (Below) to list all the files in a directory, however it doesn't work with Japanese filenames. It works fine with English filenames, but it spits out errors (Below) when I put any file containing Japanese characters in the directory. import os, glob path = 'G:\path' for infile in glob.glob( os.path.join(path, '*') ): print("current file is: ", infile) It works fine using 'PyScripter

Import a library which is in a sibling of the current folder

本秂侑毒 提交于 2020-06-24 12:08:39
问题 With the folder structure lib/ abcd/ __init.py__ lib.py app.py the code from lib.abcd import lib works. But with this file structure: bin/ app.py lib/ abcd/ __init.py__ lib.py the code from ..lib.abcd import lib gives an import error. How to do the import properly when the library is in a sibling of the current folder? (or subfolder of a sibling folder) I know that there might some hack that involves adding lib/ to the PATH, but is there an elegant Pythonic solution? If not, is there a real

Import a library which is in a sibling of the current folder

不羁的心 提交于 2020-06-24 12:06:06
问题 With the folder structure lib/ abcd/ __init.py__ lib.py app.py the code from lib.abcd import lib works. But with this file structure: bin/ app.py lib/ abcd/ __init.py__ lib.py the code from ..lib.abcd import lib gives an import error. How to do the import properly when the library is in a sibling of the current folder? (or subfolder of a sibling folder) I know that there might some hack that involves adding lib/ to the PATH, but is there an elegant Pythonic solution? If not, is there a real

Split a folder into multiple subfolders in terminal/bash script

痴心易碎 提交于 2020-06-24 07:26:29
问题 I have several folders, each with between 15,000 and 40,000 photos. I want each of these to be split into sub folders - each with 2,000 files in them. What is a quick way to do this that will create each folder I need on the go and move all the files? Currently I can only find how to move the first x items in a folder into a pre-existing directory. In order to use this on a folder with 20,000 items... I would need to create 10 folders manually, and run the command 10 times. ls -1 | sort -n |

How to change existing folder's icon via Command Line? (Windows 10)

偶尔善良 提交于 2020-06-23 11:02:48
问题 I have a folder on my desktop and 12 different icons. I want to create a scheduled task with Task Scheduler that runs as long as my PC is on and changes the icon of the folder every 15 minutes. I have done my research and I found this code: `attrib -h -r c:\test\desktop.ini echo [.ShellClassInfo] >C:\test\desktop.ini echo IconFile=%SystemRoot%\system32\shell32.dll>>C:\test\desktop.ini echo IconIndex=0 >>C:\test\desktop.ini attrib +h +r c:\test\desktop.ini attrib +r c:\test` However, I have no

How to change existing folder's icon via Command Line? (Windows 10)

丶灬走出姿态 提交于 2020-06-23 11:02:42
问题 I have a folder on my desktop and 12 different icons. I want to create a scheduled task with Task Scheduler that runs as long as my PC is on and changes the icon of the folder every 15 minutes. I have done my research and I found this code: `attrib -h -r c:\test\desktop.ini echo [.ShellClassInfo] >C:\test\desktop.ini echo IconFile=%SystemRoot%\system32\shell32.dll>>C:\test\desktop.ini echo IconIndex=0 >>C:\test\desktop.ini attrib +h +r c:\test\desktop.ini attrib +r c:\test` However, I have no

Shell script current directory?

喜欢而已 提交于 2020-06-22 05:08:56
问题 What is current directory of shell script? I this current directory from which I called it? Or this directory where script located? 回答1: The current(initial) directory of shell script is the directory from which you have called the script. 回答2: As already mentioned, the location will be where the script was called from. If you wish to have the script reference it's install location, it's quite simple. Below is a snippet that will print the PWD and the installed directory #!/bin/bash echo

Python : getcwd and pwd if directory is a symbolic link give different results

一个人想着一个人 提交于 2020-06-16 19:32:51
问题 If my working directory is a symbolic link, os.getcwd() and os.system("pwd") do not give the same result. I would like to use os.path.abspath(".") to get the full path of my working directory (or a file in it), on purpose, not to get the same result than os.path.realpath(".") . How to get, in python 2.7, something like os.path.abspath(".", followlink=False) ? Example : /tmp is a symbolic link to /private/tmp cd /tmp touch toto.txt python print os.path.abspath("toto.txt") --> "/private/tmp