To create a folder with given key name and paste contents from clipboard into it - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: To create a folder with given key name and paste contents from clipboard into it (/thread-8514.html) |
To create a folder with given key name and paste contents from clipboard into it - sibjac - Feb-23-2018 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) ''' RE: To create a folder with given key name and paste contents from clipboard into it - nilamo - Feb-23-2018 (Feb-23-2018, 04:10 PM)sibjac Wrote: but it halts and raise.Ok, so what's the error? RE: To create a folder with given key name and paste contents from clipboard into it - sibjac - Feb-24-2018 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? RE: To create a folder with given key name and paste contents from clipboard into it - sibjac - Mar-04-2018 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 ... |