python script for accessing android filesystem on windows 10 - python

I have written a script which copies all files of a particular type to a certain folder. I also wish to run this script on my connected mobile (which runs android), but I am struggling to get hold of files on my connected phone:
scr.copyfiles(r'This PC\Galaxy S7\Phone\Download\photo.jpg',dest_folder)
This returns a filenotfound error. How do I access files located on my phone?

you can write in this way
phone_dir = os.path.join('Computer', 'Galaxy S7', 'Phone', 'Download')

Related

Pulling files from real devices in appium iOS

Im having a difficult time trying to pull files and folders in one of my automated tests using appium. We use real devices for testing and I would like to use driver.pull_file() to accomplish this task. The files I want exist in the On My iPad folder, and I cannot figure out how to get the file path of the actual file in that location on the device.
Does anyone know where exactly I can find the right path? or what it would look like?
How to get the file path of a file on iOS.

How to refresh a directory (Windows 10) using python

I just need to refresh a folder.
A hypothetical ideal example would be:
from aModule import refreshdir # fake
refreshdir("C:\path\to\directory")
Context:
I am using Autodesk Desktop Connector, a service that sync data on the cloud with local folders. To avoid expending resources, this tool just checks for new updates when the user opens the file or refresh the directory (so manually). However, in order to automate some operations, I need to refresh the directory with Python. There is no API for this tool.
Thanks in advance! =)
Edit:
New files can be added in the cloud. That's why it is important to refresh the folder. Example:
Before refreshing:
enter image description here
After refreshing:
enter image description here
os.listdir cannot catch those highlited files before refreshing.
Refreshing a directory is not an operating system operation, but a function of the filesystem browser / explorer. A refresh is essentially just reading in the directory contents anew.
Most likely that Adobe tool is hooking into the filesystem functions that do this enumeration of a directory's contents. If this is the case, then the task should be as simple as
import os
os.listdir("C:/path/to/directory")
Keep in mind that backslashes (\) in standard string literals start an escape sequence, i.e. if you wanted to put an actual backslash there, you'd have to write "\\". However Windows will happily use forward slashes as directory separator as well, so you can just use that :-)
To solve this problem I created a script in Python using the pywinauto library to do a manually task that clicks on the file and then clicks on the Sync option.
In this case you'll need to know the name of the files you want to sync. The code was made to AutoCAD Plant 3D project, you'll need to change the path to your files.
from pywinauto import Application
raiz = "C:\\Users\\YOUR_USERNAME\\ACCDocs\\ORGANIZATION_NAME\\PROJECT_NAME\\Project Files\\PLANT3D_PROJ_NAME\\Plant 3D Models"
Application().start('explorer.exe ' + raiz, timeout=10)
explorer = Application(backend='uia').connect(path='explorer.exe', title="Plant 3D Models")
#Plant3DModels is a variable automatically created with the title of the windows opened
explorer.Plant3DModels.set_focus()
# 'Infra-Geral.dwg' is the name of the file that I will Sync
file = explorer.Plant3DModels.ItemsView.get_item('Infra-Geral.dwg')
file.right_click_input()
explorer.ContextMenu.Sync.invoke()

How to access files over a remote desktop connection with OS

I have a program which compares files to see which files I've updated and which files and folders are new.
I have a folder called School at home and at school with exactly the same contents in. My program works fine accessing and comparing files on my USB but I can't seem to find the correct path to access my files at school.
[EDIT]: I downloaded the rdp from my school website. To open my documents, I connect to school.rdp, type in my username and password then the window comes up.
This is the start of my program which finds the base folder
import os
# HOME, this works
print(os.path.exists("C:/School")) # True
print(os.path.exists("C:")) # True
# SCHOOL, I've tried all of these but none of them work
print(os.path.exists("N:/School")) # False
print(os.path.exists("N:/Documents")) # False
print(os.path.exists("N:")) # False
print(os.path.exists("N:/cha-sr-003/Students$/Intake2011/11FullerT/Documents/School")) # False
print(os.path.exists("//cha-sr-003/Students$/Intake2011/11FullerT/Documents/School")) # False
print(os.path.exists("cha-sr-003")) # False
Does anyone know a path which will allow me to access my folders on the remote desktop connection? If this isn't possible, is there any other way I can use to access them?
Thanks for your help
I wasn't able to access my files because I didn't have access rights to the server.
To work around this problem I used two separate programs, each which creates a .txt file in my documents at home and at school. I then copied the .txt file from my school area to my home documents and used my program compare.py to compare both of the text files
Thanks to #Jean-François Fabre and #13loodH4t for your help

Python: Navigate to portable devices directory (Windows 7)

I'm trying to solve a question I have created about how to read the recorded date of the videos I took with a windows phone. It seems that the creation date are overwritten when the files are "sync" to my computer.
I'm trying to get around this by looking at the files in the phone directly. So I need to access to
"Computer\Windows Phone\Phone\Pictures\Camera Roll"
My problem is that I can only get os.chdir() to work on paths that has C:// as root
Any suggestions?
Update
I tried to place and run a file that prints the current directory.
Which gave me the result
C:\Users\<myUser~1.COM>\AppData\Local\Temp\WPDNSE\{<a lot of numbers and dashes>}
I am not familiar with Windows Phone paths in particular, but you should be able to figure out the "real" path by using the Windows file explorer to look at the properties of a file or folder. Right-click, choose Properties and look for a Location field.
Note that some "folders", such as the ones under "Libraries", are actually XML files pointing to multiple other locations.
Maybe the phone is connect via MTP.
How to access an MTP USB device with python
could help then.
[EDIT] They mentioned calibre there. The source code of calibre mabye already contain functions for getting file informations on mobile devices.

How to extract office embedded OLE files under Linux, Nativly (Python,C,Java)?

I am trying to extract Excel Documents which embedded inside word document as OLE but its failing hard.
I need to put it in server side script so console or script is necessary. And automating Open Office is very resource hungry ..
Is there any tool or libraries to do this ? Please help..
I built a python module to do exactly this check it out over here. https://pypi.org/project/AttachmentsExtractor/ also the module can be run on Linux os.
after installing the library use the following code snippet:
from AttachmentsExtractor import extractor
abs_path_to_file='Please provide absolute path here '
path_to_destination_directory = 'Please provide path of the directory where the extracted attachments should be stored'
extractor.extract(abs_path_to_file,path_to_destination_directory) # returns true if one or more attachments are found else returns false.

Categories

Resources