How to copy entire content of a local disk in python 3.6? - copy

I want to create a .py file in Python 3.6 that will copy entire local disk partition from my PC (partition D) to external hard drive(partition E). I only managed to copy folders with distutils copytree command like this:
copy_tree(r"D:\\Myfolder", "E:\\SAVE\\Myfolder", update = True)
But I want the program to copy the entire partition with all folders subfolders and files.
Any help?

I find the answer:
import distutils
from distutils.dir_util import copy_tree
copy_tree(r"D:\\", "E:\\SAVE\\Myfolder", update = True)`
This command will copy all folders from local disk to other location.
docs

Related

Use java.io.File in PeopleCode to list files in directory

I would like to be able to create a list ,array, of file names on a folder so that I can use PeopleCode to loop through them and delete files that match a pattern and are in a date range.
I'm pretty sure I have the last half of that, matching a pattern and in a date range, but I do not know how to get the list on remote servers. I can do it on our local servers, but not remote ones.
I had hoped that this would work:
Local object &files = CreateJavaObject("java.io.File", SFO_DEL_FTP_AET.FTPDIRECTORY | "*.*");
But I don't think it is working.
Can somebody help me?
Thanks,
JPS
You can use Java to access/modify the files in a directory. Try:
Local JavaObject instead of Local object
We created a PS component to view, upload, and delete files in an App Server directory. You can see how we did it here:
https://github.com/cy2hq/PeopleSoft-Directory-Viewer

Azure Databricks: How to delete files of a particular extension outside of DBFS using python

I am able to delete a file of a particular extension from the directory /databricks/driver using the bash command in databricks.
%%bash
rm /databricks/driver/file*.xlsx
But I am unable to figure out, how to access and delete a file outside of dbfs in a python script,
I think using dbutils we cannot access files outside of DBFS and the below command outputs False as its looking in DBFS.
dbutils.fs.rm("/databricks/driver/file*.xlsx")
I am eager to be corrected.
Not sure how to do it using dbutils but I am able to delete it using glob
import os
from glob import glob
for file in glob('/databricks/driver/file*.xlsx'):
os.remove(file)

How to automatically duplicate copy contents of one folder to another folder on a different disk?

I have a folder in im c:/ drive (lets say C:\users\myname\python). Every time I create new files in that directory, is it possible to have those files automatically copy to a folder on my d: disk (d:\"magic briefcase").
The main reason I want to so this is that on my d: disk I have the "magic briefcase" of the sugarsync program set up. This lets me share the contents of that folder with my other computer in real time (which has the same "magic briefcase" folder).
since python is installed on my c: disk, I need to save my .py files on the the c disk, but of course "magic briefcase" folder is on my d: disk. So will be great to have the contents of the c: disk automatically forward to the d: disk.
Is this possible???
Thanks
Darren
mklink /J "D:\magic briefcase\python" C:\users\myname\python
should do what you want, I think.
That creates a "junction" aka hardlink between the two directories. Essentially you have one directory that's accessible via two different paths. Add a file to one of them, and it just is in the other one - no copying needed. Ditto for deletes, edits, etc.

Comparing two folders based on last modified date

I have two folders A and B, which contain identical folder structure and files, but Folder B contains modified files. Both folders contain subfolders too.
I want to check which files are modified in folder B and copy it to a different folder C.
How can I achieve this using a cmd/shell script?
AFAIK rsync and unison can't handle your needs, since you want the changes to go to a third folder C.
This code is untested:
#python
import os
import shutil
a_dir=...
b_dir=...
c_dir=...
len_a_dir=len(a_dir)
for root, dirs, files in os.walk(a_dir):
dirs.sort()
for file in sorted(files):
a_file=os.path.join(root, file)
b_file='%s%s' % (b_dir, file[len_a_dir:])
if os.path.getmtime(a_file)!=os.path.getmtime(b_file):
c_file='%s%s' % (c_dir, file[len_a_dir:])
shutil.copyfile(b_file, c_file)
Try this:
rsync -r --compare-dest=/path/to/A /path/to/B/ /path/to/C

Shadow copy to clone system volume on Windows XP

I am looking for a program that uses shadow copy to copy the contents of a Windows XP system volume that is running.
I.e. I want to clone the system volume with the following snags:
(1) I want to be able to select which files to copy (i.e. not the entire file system)
(2) This is probably implied by (1), but I also have to avoid sector-by-sector copies
(3) I do not want to clone a file system into an image file and restore to a 3rd drive but want to do a filesystem to filesystem copy
All the backup/clone utilities I looked into stumble on one of above points. Any ideas?
Perhaps this one: Hobocopy