Getting Permission denied on dirname and basename
As it stands, your script is trying to run the file named in $nquo
first with the environment variable dirn
set to the value dirname
, and then with the variable bnam
set to the value basename
. Since it is not executable, you get the error message about not being able to execute the file.
You presumably intended to run the commands on the name of the file, which requires either back-ticks or (preferably) $(...)
around it:
dnam=$(dirname "$nquo")
bnam=$(basename "$nquo")
open(filename, 'w+') causes Permission Error 13
Look the way you handle paths its very dangerous.
its better if you use "OS"
import os
from tkinter import filedialog
path_to_file = filedialog.askopenfilename(title = "Select a JSON file")
dir_path= os.path.abspath(os.path.dirname(path_to_file))
basename = os.path.abspath(os.path.basename(path_to_file))
fileName = basename.split('.json')[0] + '.csv'
csv_filename = os.path.join(basename, fileName)
Trying to create empty php file gives failed to open stream permission denied wordpress
Finally I find a fix that fulfill my requirement and I am posting here in case anybody faces same situation. Rather creating file in active theme folder, I created a template file in the plugin and used below code to load the template.
function my_page_template($page_template){
$slug = 'slug of the page where to load my custom template';
if ( is_page($slug) ) {
$page_template = dirname( __FILE__ ) . '/templates/my-template.php';
}
return $page_template;
}
add_filter( 'page_template', 'my_page_template');
NOTE: This code will not list the template name in the templates listing dropdown (Template) option of pages. It will load the custom template irrespective to assigned template from the admin panel of the pages.
os.path.dirname() and os.path.basemane() are giving weird results
OSX, just like Linux, uses /
as a separator. You can get the standard separator for your OS from os.path.sep
.
>>> import os
>>> os.path.sep
'/'
>>> path='/Users/apple/Documents/list.txt'
>>> os.path.dirname(path)
'/Users/apple/Documents'
>>> os.path.basename(path)
'list.txt'
Notice that os.path
is just constructing "correct" paths, it does not do any checking, if files exist. That would not make much sense, if you constructed a path to create a new file. You could use os.path.exists()
for that.
How to Zip a file/folder from QTreeView - PermissionError: [Errno 13] Permission denied:
dpath error...change to a user directory...new code
def zip_file(self,):
dpath = r'C:\Users\Black Laptop\Desktop\DC.zip'
if os.path.isfile(self.path):
with ZipFile(dpath, 'w') as zip:
zip.write(self.path, basename(self.path))
print('file zipped successfully!')
else:
zf = zipfile.ZipFile(dpath, "w", )
for dirname, subdirs, files in os.walk(self.path):
zf.write(dirname, basename(dirname))
for filename in files:
zf.write(os.path.join(dirname, filename), basename(os.path.join(dirname, filename)))
zf.close()
print('All files/folders zipped successfully!')
Segmentation fault occurs because of dirname api for some particular strings (like . and usr)
You don't include libgen.h thus dirname is not declared thus it is assumed to return an int thus your program is corrupted and you get a segfault.
Related Topics
Apache/Httpd /Var/Www/HTML/ .Cgi Scripts Throw 500 Internal Server Error
Avoid Daemon Running in Dedicated CPU Cores
Shared Libraries (Dlopen) and Thread-Safety of Library Static Pointers
Unzip in Current Directory While Preserving File Structure
Reset Bash History Search Position
Update .Bashrc from Provisioning Shell Script with Vagrant
Detect When Reader Closes Named Pipe (Fifo)
What's a Simple Method to Dump Pipe Input to a File? (Linux)
Qt - How to Detect Whether The Application Is Running on Gnome or Kde
Goroutine in Io Wait State for Long Time
How to Delete 5 Lines Before and 6 Lines After Pattern Match Using Sed
What Means "Atomic" System Call
Will Java Compiled in Windows Work in Linux
Python3 No Such File or Directory
Tk Initialization Failed: No Display Name and No $Display Environment Variable