1

I have a problem using pyperclip. I have to upload a bunch of documents to the web. I used the join method to make a string of the files contained in a specific folder. The problem comes when that string reaches 260 characters. pyperclip copies up to 260, the rest is not copied. Is there a way I can change this? Or another method I can use?

from os import listdir
from os.path import isfile, join
cell1 = str(cell1)
my_path = "C:\Users\\"+user+"\Desktop\folder\\"+cell1
onlyfiles = [f for f in listdir("C:\Users\\"+user+"\Desktop\folder\\"+cell1) if isfile(join(my_path, f))]
for doc in onlyfiles:
    doc = '" "'.join(map(str, onlyfiles))
    docs = '"' + doc + '"'
print docs
time.sleep(1)
#copiar directorio
from pyperclip import copy
copy(my_path)
keyboard.press(Key.ctrl)
keyboard.press('v')
keyboard.release(Key.ctrl)
keyboard.release('v')
time.sleep(1.5)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Noelia
  • 41
  • 4
  • Your code snippet is not complete since you show no import for `keyboard`. Please show a complete example, as in [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). It also is not wise to directly import the `copy` function into your namespace, since that is such a common method name. Better to use `import pyperclip` and `pyperclip.copy(my_path)`. Have you tried using pyperclip with longer strings in a simpler example? – Rory Daulton Aug 14 '18 at 13:28
  • (I'm sorry if I have any grammatical mistake, I'm a Spanish speaker). The keyboard import is in the beginning of my code, that is why I did not paste it. There is sensible information in the middle. This is a task I have been working for my job, and I want to try it for what it is thought for: mass upload of documents to the web. I'll add import pyperclip and pyperclip.copy(my_path). Thanks! – Noelia Aug 14 '18 at 13:41
  • I'm the creator of Pyperclip and can vouch that it doesn't have a built-in limit. On Windows 10, Python 3.7, I can run this to confirm it: >>> import pyperclip >>> pyperclip.copy('x' * 10000) >>> len(pyperclip.paste()) 10000 – Al Sweigart Aug 21 '18 at 22:17
  • Hi! I found out that there is a limit of characters in the space where I have to paste the string I made with all the names of the documents contained in a certain folder. So now I'm dealing with another trouble. What I'm going to do is write a loop in order to upload documents every x quantity. It's going to be tedious, but I just can't bear the idea of controlling the keyboard to type a "CTRL"+"A", and use "TAB" because is embarrassing! haha! THANKS for your response!! I'll be migrating to W10 in a month (sorry for the typo), so I hope everything is going to behave properly! =) – Noelia Aug 24 '18 at 02:19

1 Answers1

1

I think you're getting truncated file names from listdir - there is apparently a 260 character path length limit on Windows.

kristaps
  • 1,705
  • 11
  • 15
  • Is there a way I can change that on W7? I'm no programmer, I've barely started with Python a few months ago. – Noelia Aug 14 '18 at 13:46
  • [This blog post](https://www.burgaud.com/path-too-long) says there might be a workaround - prefix the path with "\\?\". Change `my_path = "C:\\...` to `my_path = "\\\\?\\C:\\...` and see if it helps – kristaps Aug 14 '18 at 14:43