How to access files over a remote desktop connection with OS - python

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

Related

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 include data files and directories that need to be changed or added with Pyinstaller?

The script needs to read from a .txt file with a list of items and based off that list, it creates a directory for each item. So just a simple with open() statement and then os.mkdir()..
The client will add account names to the txt file when they get new accounts, the program will create new directories for those new accounts. Files that are then placed in each directory for those accounts will get pandas stuff done to them and moved to an archive folder along with logging the events.
Since the program will be used by non-programmers, I'm using Pyinstaller.
When I go through the process, including the --add-file attribute, run the program, it says the txt file doesn't exist. I think I have an idea how to fix that but when I got the os.mkdir and with open statements to work by separating them out, it created them in the home folder and not the program folder. Path issue? And I only see documentation on how to include data files but not how to include changeable files.

python script for accessing android filesystem on windows 10

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')

How to set up the filepath in code to make it runnable for others

I build a small project in python, now I need to send to another user to make him run it. But if he downloads my code on his computer then the file path(which based on my computer) won't be valid anymore. Is there anything I can do to make it runnable for him by setting up the path correctly?
zip the folder that it is located in and have them place it in the same location i.e if it is in your documents folder have them place it there

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.

Categories

Resources