Python Forum
To create a folder with given key name and paste contents from clipboard into it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To create a folder with given key name and paste contents from clipboard into it
#1
I got stuck here... This is working fine up to this... I was trying to make it create a folder named same as the "key" and paste the contents of the clipboard into it, but it halts and raise. I am literally at loss with the code being a newbie, whatever I tried to make it work is in vain. The function is: It collects assigned files for the corresponding user from an ecxel column range and copy them into a clipboard and then prompt to manually select the folder and paste in it. Would be greatful helping with making this work.

import os
import xlrd

def Is64Windows():
    return 'PROGRAMFILES(X86)' in os.environ

def GetProgramFiles32():
    if Is64Windows():
        return os.environ['PROGRAMFILES(X86)']
    else:
        return os.environ['PROGRAMFILES']

def GetProgramFiles64():
    if Is64Windows():
        return os.environ['PROGRAMW6432']
    else:
        return None


filesToSearch = ""

DEBUG = False

print 'Enter Excel Filename==>'
if DEBUG:
    fileToScan = 'sample.xlsx'
else:
    fileToScan = raw_input()

workbook = xlrd.open_workbook(fileToScan)
worksheet = workbook.sheet_by_name('Sheet1')
numberOfRows = worksheet.nrows 
numberOfColumns = worksheet.ncols

print 'Enter Column To Scan For Filenames==>'
if DEBUG:
    columnToScan = 'A'
else:
    columnToScan = raw_input()

columnToScan = columnToScan.lower()
columnToScan = ord(columnToScan)-97

print 'Enter Column To Scan For Persons Assigned Work==>'
if DEBUG:
    personColumn = 'B'
else:
    personColumn = raw_input()

personColumn = personColumn.lower()
personColumn = ord(personColumn)-97

print 'Enter Drive To Search For File==>'
if DEBUG:
    drive = 'C'
else:
    drive = raw_input()

assignedWork = {}

currentCell = 0
while currentCell < numberOfRows:
    cellFileValue = str(worksheet.cell_value(currentCell, columnToScan))
    cellPersonValue = str(worksheet.cell_value(currentCell, personColumn))
    
    if cellPersonValue not in assignedWork.keys():
        assignedWork[cellPersonValue] = ""
    
    assignedWork[cellPersonValue] = assignedWork[cellPersonValue] +', '+str(cellFileValue)+'.*'
    currentCell += 1

#print assignedWork
    
def searchFiles(filesToSearch):
    #Remove starting space and comma
    filesToSearch = '"' + filesToSearch[2:] + '"'
    #print filesToSearch
    
    if Is64Windows():
        os.system('SearchMyFiles_64.exe /FilesWildCard '+filesToSearch+'  /ScanSubfolders 1 /BaseFolder "'+drive+':\" /scomma results.txt /StartSearch ')
    else:
        os.system('SearchMyFiles.exe /FilesWildCard '+filesToSearch+'  /ScanSubfolders 1 /BaseFolder "'+drive+':\" /scomma results.txt /StartSearch ')

    filesFound = []
    filePathsFound = []
    with open('results.txt') as fread:
        for line in fread:
            filename = line.split(",")[0]
            path = line.split(",")[1]
            path = path.split(",")[0]
            #os.system('explorer '+'"'+path+'"')
            filesFound.append(path+'\\'+filename)
            filePathsFound.append(path)
            
        #print filesFound
    filesFoundString = ""
    for f in filesFound:
        filesFoundString += '"'+f+'" '

    print filesFoundString
    
    if filesFound:
        os.system('java File2Clip '+filesFoundString)
    else:
        print 'No Files Found'
        

for key, value in assignedWork.iteritems():
    print 'Searching For Files To Be Assigned To '+key
    searchFiles(value)
    print 'Paste The Files, Press ENTER When Done'
    raw_input()
    
'''
filesFoundString = ""
for f in filesFound:
    filesFoundString += '"'+f+'" '

print filesFoundString
os.system('File2Clip '+filesFoundString)
'''
Reply
#2
(Feb-23-2018, 04:10 PM)sibjac Wrote: but it halts and raise.
Ok, so what's the error?
Reply
#3
Hi, @nilamo,
Thank you for your prompt reply.

Whatever I do, I am not able to make it create a folder and paste the clipboard contents. It does not show any errors. Just gets closed itself. Sorry for misleading, it does not raise. Will it be possible to make it create a new folder with the "key" and paste the clipboard contents into it?
Reply
#4
Please help me with the above script
The the script will scan an excel file(xls/xlsx) where 2 colums <x> and <y>
are defined as:
<x> file
<y> person to assign the <x> file

The script will then search files the files on system and
copy the files to clipboard so that it can be pasted to the
desired location and this will be done for every unique <y> person.

The script works fine till there. Please help me to make the script to automatically paste the clipboard content to a folder created on the name of each "unique y" person, where y is the search keyword. I am stuck here were I can make it create a folder name with os.makedirs with "sellPersonValue" as the folder name not the actual "unique y" person name. Will it be possible for the script to create a folder named with "unique y" and then paste the content into it each time automatically or with a raw input is given? I feel like Tkinter or Pyperclip, maybe be of help, but really at loss how to inco-orporate it into this script. Please Please help me ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create dual folder on different path/drive based on the date agmoraojr 2 431 Jan-21-2024, 10:02 AM
Last Post: snippsat
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 532 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  What script to paste folders thenewcoder 1 664 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  non-latin characters in console from clipboard Johanson 3 691 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Please help me [copy and paste file from src to dst] midomarc 2 1,010 Nov-24-2022, 10:13 PM
Last Post: midomarc
  saving and loading text from the clipboard with python program MaartenRo 2 1,657 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,473 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  ImageTk Paste KDog 14 6,906 Jun-27-2021, 11:07 AM
Last Post: KDog
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,470 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Cut and Paste Oshadha 3 2,433 Jan-20-2021, 04:27 PM
Last Post: spaceraiders

Forum Jump:

User Panel Messages

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