Raspberry Pi, the soon to be released $35 arm computer has a limited amount of USB ports. If you need to copy a file to a usb drive you will have to unplug your keyboard. Luckily, I have written a small python script that will solve this potential headache.
import time
import string
import os
import sys
lastspace = False
os.system("rm cat.txt cat2.txt device.txt")
if (len(sys.argv) > 1):
movefile = sys.argv[1]
else:
movefile = raw_input('Enter your file to be moved: ')
os.system("ls /media/ >> cat.txt")
raw_input('Press Enter and then insert USB device')
time.sleep(11)
os.system("ls /media/ >> cat2.txt")
os.system("diff cat2.txt cat.txt >> device.txt")
file = open("device.txt", "r")
device = file.read()
dlist = string.split(device,'<')
print device
print dlist
dlist[1] = string.strip(dlist[1],"\n")
x = 0
newfile = dlist[1]
while (x < len(dlist[1])):
if(dlist[1][x] == " " and lastspace == False and x != 0):
newfile = newfile[0:x-1] + "\ " + newfile[x:]
lastspace = True
if (dlist[1][x] == " " and x == 0):
newfile = newfile[1:]
if lastspace == True:
x = x+1
x = x+1
print "mv " + movefile + " /media/" + newfile + "/"
os.system("mv " + movefile + " /media/" + newfile + "/")
You can either enter your file name as an argument or it will prompt you. You can also tweak the waiting time that it takes before trying the move. I’m not sure how accurate the technique I have used to test for new devices is. But I thought it would be the easiest way. Actually I’m pretty sure there has to be a more efficient way, but I didn’t want to implement a continuously polling program. I will definitely take suggestions and feedback in order to make it better.
Popularity: 1% [?]