Issue while creating a directory
Hey, I am trying to run a Django application . There is a section where I want to create a directory programmatically. When I am trying to create a directory, it is not giving any error, but it is not creating the directory. could you please help me to find the solution?
20 Replies
Project ID:
06a78b22-a3ba-46f2-a16d-2f2ee81b0ed9
06a78b22-a3ba-46f2-a16d-2f2ee81b0ed9
does this work locally
Yes. It works locally
what directory are you creating these subdirectories in
current_dir = os.getcwd()
output_dir = "store/random_string"
full_output_dir = os.path.join(current_dir, output_dir)
if not os.path.exists(full_output_dir):
print('PATH DOESNOT EXISTS- CREATING')
os.makedirs(full_output_dir)
else:
print('PATH EXISTS CONTINUING')
There is a directory named "store" in the project. I am trying to create a directory inside the "store" directory. Above is the code snippet
I see two print statements there, and neither of them print on railway?
print('PATH DOESNOT EXISTS- CREATING')
This is getting printed. But the directory is not getting created
check for errors from os.makedirs
try:
os.makedirs(full_output_dir, exist_ok=False)
print('NO ERRORS')
except Exception as e:
print(e)
I tried this. There are no errors.
okay and what makes you think the directory wasn't created
There is another function that uses the newly created directory. When I run that function, I am getting error directory doesn't exist.
For confirming it, I made a simple view to check the contents of the directory, Below is the code.
def testDirView(request):
dir = request.GET.get('dir')
directories = [name for name in os.listdir(dir)]
print('DIR--->> ',directories)
return HttpResponse("DONE")
This doesn't print the newly created directory.
okay I will do some tests tomorrow as it's very late for me right now
ok. Thanks. 🙂
you keep debugging this too!
sure.
im sorry i couldn't reproduce your issue
this was the code i used
what directory did you set in this request
Hey, I found the issue. It was because I was running two services (celery and web ). I was trying to create a new directory inside the celery service. I changed the logic and tried to create the directory in web service and it worked . I don't know why this issue was happening. I tried to find the reason, but I couldn't.
happy you could solve it