Python Forum
Select next file in directory and keep track of what's already been selected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select next file in directory and keep track of what's already been selected
#1
I need to make a python script where it'll select the next file in a currently open directory that it hasnt already selected. it needs to work with the upload window in chrome browser (the same window that opens when u press a "browse for file to upload" button on any generic website).



here are extra details:

windows 7

When it selects a file, i need to output the file name & path to a log-type csv file, where all previously selected files are collected.

When it runs the script the next time, it should then select the next file in the currently opened directory that it hasnt previously written in the log file.

The script does not need to open or upload the file, it only needs to select it.



I have searched and searched for a way to do this, and the only results are "how to list files in a directory" and similar things. could anybody help out? I'm open to other suggestions besides a csv file, i just need the script to be able to remember whats already been selected. I'm a beginner to python scripting but i have true coders helping me out, i just need ideas/help that they will be able to understand.

also posted this question here, but no replies yet:
https://stackoverflow.com/questions/5489...n-selected
Reply
#2
What does "select" mean, in this context?

I'd be surprised if you could do anything to the file upload dialog in a browser. That'd be a major security hole, and browsers don't normally leave too many of those open.
Reply
#3
(Feb-27-2019, 10:55 PM)nilamo Wrote: What does "select" mean, in this context?

I'd be surprised if you could do anything to the file upload dialog in a browser. That'd be a major security hole, and browsers don't normally leave too many of those open.

Select means... like the same way it'd look when you click on the file with the mouse.

Can we do it in normal windows explorer then, and have winautomation (auto mouse/keyboard contoller program) ctrl+drag it to the chrome UL window? That way it'd be automatically selected to upload, just won't be in the same folder which is fine.

if you run
pip install pyperclip
in cmd and then run the code I just built

import subprocess
import pyperclip #cross-platform clipboard module
path = pyperclip.paste() #grabs the clipboard & pastes it as variable "path"
extra = r'"' + path + '"' #combines extra code to get ready for subprocess module
subprocess.Popen('explorer /select, ' + extra)
print(extra)
then it'll grab the path from the clipboard & open an explorer window that'll auto select the file in the path. (this assumes the clipboard looks like D:\Documents\Downloads\AutomationTesting\2019-02-25\BE007-BAGedge 6 oz. Canvas Promo Tote-BLACK.jpg or similar.)

what i don't know is how to build on this to put the path in the clipboard, including the file name, and have it auto change to the next file every time.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,076 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 928 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,064 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,492 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 984 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 1,616 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,523 Sep-12-2022, 04:50 AM
Last Post: python202209
  select files such as text file RolanRoll 2 1,129 Jun-25-2022, 08:07 PM
Last Post: RolanRoll
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,330 May-17-2022, 07:49 AM
Last Post: Pedroski55
  How to read python shortcut target profile directory of Chrome Ink file sunny9495 1 1,617 Apr-12-2022, 06:12 PM
Last Post: sunny9495

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020