directory

Recursively create directories prior to opening file for writing

时光怂恿深爱的人放手 提交于 2021-01-27 06:49:05
问题 I need to write to a file (truncating) and the path it is on itself might not exist). For example, I want to write to /tmp/a/b/c/config , but /tmp/a itself might not exist. Then, open('/tmp/a/b/c/config', 'w') would not work, obviously, since it doesn't make the necessary directories. However, I can work with the following code: import os config_value = 'Foo=Bar' # Temporary placeholder config_dir = '/tmp/a/b/c' # Temporary placeholder config_file_path = os.path.join(config_dir, 'config') if

Python: Check if any file exists in a given directory

只谈情不闲聊 提交于 2021-01-27 04:54:28
问题 Given a directory as a string, how can I find if ANY file exists in it? os.path.isFile() # only accepts a specific file path os.listdir(dir) == [] # accepts sub-directories My objective is to check if a path is devoid of files only (not sub-directories too). 回答1: To only check one specific directory, a solution like this would suffice: from os import listdir from os.path import isfile, join def does_file_exist_in_dir(path): return any(isfile(join(path, i)) for i in listdir(path)) To dissect

Python: Check if any file exists in a given directory

三世轮回 提交于 2021-01-27 04:53:59
问题 Given a directory as a string, how can I find if ANY file exists in it? os.path.isFile() # only accepts a specific file path os.listdir(dir) == [] # accepts sub-directories My objective is to check if a path is devoid of files only (not sub-directories too). 回答1: To only check one specific directory, a solution like this would suffice: from os import listdir from os.path import isfile, join def does_file_exist_in_dir(path): return any(isfile(join(path, i)) for i in listdir(path)) To dissect

How to limit folder/file access to a program only?

*爱你&永不变心* 提交于 2021-01-27 04:06:53
问题 Okay, so I am creating a c# winforms application. I want to write/read from binary data file. But, I want to put that file in a folder somewhere and I do not want anyone to be able to delete or edit the file. I only want the program that uses the file to be able to access it. Is this possible? I looked into MSDN's structure on file security and as I researched it I saw people complain that if you limit the file to a user then that person can just override the privileges and make it editable.

How can I limit the max numbers of folders that user can create in linux

偶尔善良 提交于 2021-01-24 09:07:22
问题 Since I have been told that if a user in my computer will create "infinite" number of folders / files (even empty) it can cause my computer to become much much slower (even stuck), I want to limit the maximum number of files/directories that user can create. I'm afraid that one user will try to create a huge number of files and it will become a problem for all the other users, so it will be a security issue, How do I do that, how do I limit the max number of files/directories each user can

python - numpy FileNotFoundError: [Errno 2] No such file or directory

南笙酒味 提交于 2021-01-24 07:04:11
问题 I have this code: import os.path import numpy as np homedir=os.path.expanduser("~") pathset=os.path.join(homedir,"\Documents\School Life Diary\settings.npy") if not(os.path.exists(pathset)): ds={"ORE_MAX_GIORNATA":5} np.save(pathset, ds) But the error that he gave me is: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Maicol\\Documents\\School Life Diary\\settings.npy' How can I solve this? The folder isn't created... Thanks 回答1: Looks like you're trying to write a file to

python - numpy FileNotFoundError: [Errno 2] No such file or directory

荒凉一梦 提交于 2021-01-24 07:02:50
问题 I have this code: import os.path import numpy as np homedir=os.path.expanduser("~") pathset=os.path.join(homedir,"\Documents\School Life Diary\settings.npy") if not(os.path.exists(pathset)): ds={"ORE_MAX_GIORNATA":5} np.save(pathset, ds) But the error that he gave me is: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Maicol\\Documents\\School Life Diary\\settings.npy' How can I solve this? The folder isn't created... Thanks 回答1: Looks like you're trying to write a file to

How do I link back out of a folder using the a-href tag? [duplicate]

ぐ巨炮叔叔 提交于 2021-01-20 20:12:45
问题 This question already has answers here : Having links relative to root? (6 answers) Closed 7 years ago . Alright so I have a page in a folder, the page is called jobs.html and the folder is simply called "jobs". Its a sub folder of my mine "website" folder. In the main directory of the "main" folder is my "home.html" file. When I try to do <a href="home.html">bla</a> It malfunctions as it is looking for the home file in the jobs folder, which does not exist. So I ask, how can I reference out

How do I link back out of a folder using the a-href tag? [duplicate]

大憨熊 提交于 2021-01-20 20:11:50
问题 This question already has answers here : Having links relative to root? (6 answers) Closed 7 years ago . Alright so I have a page in a folder, the page is called jobs.html and the folder is simply called "jobs". Its a sub folder of my mine "website" folder. In the main directory of the "main" folder is my "home.html" file. When I try to do <a href="home.html">bla</a> It malfunctions as it is looking for the home file in the jobs folder, which does not exist. So I ask, how can I reference out

How do I link back out of a folder using the a-href tag? [duplicate]

别等时光非礼了梦想. 提交于 2021-01-20 20:08:55
问题 This question already has answers here : Having links relative to root? (6 answers) Closed 7 years ago . Alright so I have a page in a folder, the page is called jobs.html and the folder is simply called "jobs". Its a sub folder of my mine "website" folder. In the main directory of the "main" folder is my "home.html" file. When I try to do <a href="home.html">bla</a> It malfunctions as it is looking for the home file in the jobs folder, which does not exist. So I ask, how can I reference out