Feb-17-2018, 11:50 AM
Feb-17-2018, 01:28 PM
You can use the
__file__
variable. Here is a way to create a directory named 'foo' with the standard pathlib modulefrom pathlib import Path p = Path(__file__).resolve().parent/'foo' if not p.is_dir(): p.mkdir()
Feb-17-2018, 03:53 PM
(Feb-17-2018, 01:28 PM)Gribouillis Wrote: [ -> ]You can use the__file__
variable. Here is a way to create a directory named 'foo' with the standard pathlib module
from pathlib import Path p = Path(__file__).resolve().parent/'foo' if not p.is_dir(): p.mkdir()
i used this
def make_file(): os.getcwd() os.chdir('export') os.mkdir(str(name.get()))it works as intended once now its like this
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\HOME-PC\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args) File "C:\Users\HOME-PC\Desktop\program_thing\tkinter_program.py", line 20, in make_file os.chdir('export') FileNotFoundError: [WinError 2] The system cannot find the file specified: 'export'
Feb-17-2018, 05:30 PM
Why not use my code? It is very good. In your code the
os.getcwd()
gets the current working directory but it does nothing with it, so you can safely remove this line. The os.chdir('export')
tries to change the current directory by going to a directory named 'export', but it fails because there is no such directory. Finally the name.get()
in the last statement won't work because the variable name
is not defined. Or may be it is a tkinter variable in your program?Feb-17-2018, 06:02 PM
(Feb-17-2018, 05:30 PM)Gribouillis Wrote: [ -> ]Why not use my code? It is very good. In your code theos.getcwd()
gets the current working directory but it does nothing with it, so you can safely remove this line. Theos.chdir('export')
tries to change the current directory by going to a directory named 'export', but it fails because there is no such directory. Finally thename.get()
in the last statement won't work because the variablename
is not defined. Or may be it is a tkinter variable in your program?
export does exist and the name.get is part of a folder creation system
Feb-17-2018, 06:02 PM
Put a print statement around
Look if you can reach from this path 'export'. I think your cwd is at a different path
as the directory 'export'.
By the way,
If you want to read/write file, use
After you've understood the old school os.path and the difference between relative and absolute paths, you should take a look into the pathlib module.
os.getcwd()
def make_file(): print('Current working directory', os.getcwd()) os.chdir('export') os.mkdir(str(name.get()))Execute the program and look in which current working directory your program is running.
Look if you can reach from this path 'export'. I think your cwd is at a different path
as the directory 'export'.
By the way,
os.mkdir
makes a directory, not a file.If you want to read/write file, use
open(filepath)
.After you've understood the old school os.path and the difference between relative and absolute paths, you should take a look into the pathlib module.
Feb-17-2018, 06:06 PM
(Feb-17-2018, 06:02 PM)SteampunkMaverick12 Wrote: [ -> ]the name.get is part of a folder creation systemWhat does this mean ?
Feb-18-2018, 03:20 PM
(Feb-17-2018, 06:02 PM)DeaD_EyE Wrote: [ -> ]Put a print statement aroundos.getcwd()
def make_file(): print('Current working directory', os.getcwd()) os.chdir('export') os.mkdir(str(name.get()))Execute the program and look in which current working directory your program is running.
Look if you can reach from this path 'export'. I think your cwd is at a different path
as the directory 'export'.
By the way,os.mkdir
makes a directory, not a file.
If you want to read/write file, useopen(filepath)
.
After you've understood the old school os.path and the difference between relative and absolute paths, you should take a look into the pathlib module.
its supposed to be a folder
i am trying to make a program that makes a folder. Then you can make and save files in the folder. Its supposed to b a game modding program