I have a program that makes calculus, converts different data and plots it while saving it in different directories. So far, so good BUT. Whenever I want to move the files generated to another folder without closing Python it doesn't let me only with one of them, telling me that a program still has it open and I can't move it. The weird part is that I can take out all the plots generated so it's the folder itself that can't be moved. I don't know what to do because other folders are generated and treated the same way and don't give me problems. Any idea?
TL;DR: Can't move a empty folder while Python is still open
path_data_anaconv = path_data + r'TheProblem/'
if not os.path.exists(path_data_anaconv):
os.makedirs(path_data_anaconv)
Related
I am wondering if there is an easy way to access 'parallel' directories (See photo for what I am talking about... I don't know what else to call them, please correct me if they are called something else!) from a Python file without having to input the string path.
The basic structure I intend to use is shown in the picture. The structure will be used across different computers, so I need to avoid just typing in "C:\stuff_to_get_there\parent_directory\data\file.txt" because "C:\stuff_to_get_there" will not be the same on different computers.
I want to store the .py files in their own directory, then access the data files in data directory, and save figures to figures directory. I was thinking of trying os module but not sure if that's the correct way to go.
parent directory
scripts
.py files
figures
save files here
data
.txt files stored here
Thanks for any help!
I'm writing a post-job script for Thinkbox Deadline. I need the directory for the rendered frames from a finished Cinema 4D job.
In Cinema, we had the frames know to go up a few directories, then back down to a different location by using this syntax "path\to\c4d_file..\..\renders\frame_00.png"
In this example the "\.." tells Cinema to go up 2 folders to the "path" folder then back down into the "renders" folder where it saves the renders to.
Unfortunately Deadline doesn't calculate the actual path when it makes the render job. When I tell the post-job script to go to the path location, it doesn't understand the '\..' -- so I need to tell it where to go up a directory and where to go back down.
Is there any sort of Python magic that can basically read the "\.." and know how to make the correct directory?
Thanks
Take the absolute path and remove the last one
path.sep.join(path.abspath('.').split(path.sep)[:-1])
I started moving parts of code outside my jupyter notebooks. I am new in Python and want to make everything right from the beginning. I have a following project structure.
Using data/raw/filename obviously doesn't work, I have to go one level up. Like:
with open ('../data/dumps/df_aggregated.dmp', 'rb') as fp:
df_aggregated = pickle.load(fp)
I think I can save my absolute path to data somewhere in a python script, but I have some doubts if it is right. What if I execute a script/a notebook from a nested folder?
Please help me to understand how to arrange my folders and make it flexible
This'll be a bit long winded but might be best to explain the scenario first...
We have a number of BI visualizations that are generated each month for management reporting. Just over 400 images are taken each month and automatically placed in a directory using WKHTMLTOIMAGE. These images are automatically updated in to various PowerPoint presentations and emailed off to the relevant teams. All of this "generally" works fine and has removed much of the tedious manual work.
The problem occurs when one of these visualizations fails to update. At the moment there is no way of checking, other than to open up each visualization and compare it to the image that has just been extracted.
If 399 of the 400 images work, and the 400th doesn't, PowerPoint would still be populated using the previously loaded (400th) image due to the way the "Link to File" function works in PowerPoint.
What I'd like to do is use an example image (check.jpg) to overwrite all of the existing images but still keeping their original file names. That way when the monthly report is run if one of them doesn't work the PowerPoint would have still been updated with this check.jpg image which would stand out as something we would need to rerun manually.
I can't seem to find anything along the lines of what I'm looking for. I can list all of the filenames, move them, overwrite them etc but not sure how I'd do it (or even if it's the right way to do it) with the scenario I'm thinking of. If someone could point me in the right direction, that'd be great. Thank you.
Opening a file for writing doesn't change the filename:
with open("path/to/check.jpg", "rb") as src, open("path/to/image.jpg", "wb") as dest:
dest.write(src.read())
I'm currently writing a little program to "reset" hard drives. In this program the user should be able to choose if he wants to have everything deleted completely or just a part of it, e.g a special folder.
Since I want to provide anonymousity to all pre-owners, I want to completely delete the folder or the drive, essentially I want to format a single folder.
The problem is, that with file recovery tools it is very easy to restore deleted files, since they are mostly not erased but just thrown out of the file system. How can I set all bytes that were taken by the folder and the files in it to Zero, or at least make them inrepairable?
I'm using python 2.7 and Debian
I found exactly a solution! Perfect!
https://manpages.debian.org/stretch/manpages-de/shred.1.de.html
You can shred files and directorys and whole partitions with it and it is for DEBIAN!!! You can set all bytes to zero if you want and many more options! Great command for such jobs!