06-16-2011
Help improve python sortfile by extension and size
Hi i had this python script to sort source dir by file extension and cp to individual extension destination dir. i would like to ask on how to add an option for size sorting somewhat like
# <script.py> -size <range 10k-20k>,<range 30k-40k>,..... source destination
Im a beginner and doing my homeworks for this one. Hope someone can add to the scripts.
Quote:
import os
import os.path
import shutil
import sys
source = sys.argv[1]
destination = sys.argv[2]
while not os.path.exists(source):
source = raw_input('Enter a valid source directory\n')
while not os.path.exists(destination):
destination = raw_input('Enter a valid destination directory\n')
for root, dirs, files in os.walk(source, topdown=False):
for file in files:
extension = os.path.splitext(file)[1][1:].upper()
destinationPath = os.path.join(destination,extension)
if not os.path.exists(destinationPath):
os.mkdir(destinationPath)
if os.path.exists(os.path.join(destinationPath,file)):
print 'WARNING: this file was not copied :' + os.path.join(root,file)
else:
shutil.copy2(os.path.join(root,file), destinationPath)
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Wrote this script to find the date x days before or after today. Is there any way that this script can be speeded up or otherwise improved?
#!/usr/bin/sh
check_done() {
if
then
daysofmth=31
elif
then
if
... (11 Replies)
Discussion started by: blowtorch
11 Replies
2. IP Networking
I am currently experiencing the file size being added to the file extension when transfering information from Command Line Client to a UNIX server. Does anyone know why this is happening and how do I stop the file size being added to the file extension.
Example: football.pqt.11108... (1 Reply)
Discussion started by: Skeeterrock
1 Replies
3. UNIX for Dummies Questions & Answers
Command ls -l *cpp lists all cpp program files in a directory. It shows the size of each file. Using a calculator to work out the total size of the cpp files would be very tedious.
Is there a way to get the total size from the command line? (5 Replies)
Discussion started by: resander
5 Replies
4. IP Networking
I have a 10Gbps network link connecting two machines A and B. I want to transfer 20GB data from A to B using TCP. With default setting, I can use 50% bandwidth. How to improve the throughput? Is there any way to make throughput as close to 10Gbps as possible? thanks~ :) (3 Replies)
Discussion started by: andrewust
3 Replies
5. Shell Programming and Scripting
Hi
I Have a directory and i have some files below
abc.txt
abc.gif
gtee.txt
ghod.pid
umni.log
unmi.tar
How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies
6. Shell Programming and Scripting
I am working on requirement on spreadsheet in python scripting.
I have a spreadsheet containing cell values and with background color.
I am able to read the value value but unable to get the background color of that particular cell.
Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies
7. UNIX for Dummies Questions & Answers
Hi All,
I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing.
1.I need to display the .done files from the directory.
2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory
... (2 Replies)
Discussion started by: girija.g6
2 Replies
8. Windows & DOS: Issues & Discussions
Hi all,
I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine..
Below is the code I am trying:
#!/usr/bin/env python
import wmi
c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies
9. Programming
Hi all...
As you know I like making code backwards compatible for as many platforms as possible.
This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
LEARN ABOUT DEBIAN
yhsm-yubikey-ksm
yhsm-yubikey-ksm(1) General Commands Manual yhsm-yubikey-ksm(1)
NAME
yhsm-yubikey-ksm - Decrypt YubiKey OTPs using an attached YubiHSM
SYNOPSIS
yhsm-yubikey-ksm --key-handles ... [options]
DESCRIPTION
This is a small network server with a REST-like API that decodes YubiKey OTPs.
It can be used as a decryption backend (Key Storage Module) to a validation service such as the YubiCloud.
The AES keys of the YubiKeys must be present as AEAD files decryptable to the attached YubiHSM. Such AEADs can for example be created using
yhsm-import-keys(1).
Note that this daemon is single threaded - it will only handle a single request at once. A request timeout is therefor most important.
OPTIONS
-D, --device
device file name (default: /dev/ttyACM0)
-v, --verbose
enable verbose operation
--debug
enable debug printout, including all data sent to/from YubiHSM
--U, --serve-url base
base of URL for decrypt web service (default: /yhsm/validate?)
--port num
port to listen on (default: 8002)
--addr addr
address to bind to (default: 127.0.0.1)
--key-handles kh, --key-handle kh
key handles to use for decoding OTPs. Examples : "1", "0xabcd".
--aead-dir dir, -B dir
base directory for AEADs (default: /var/cache/yubikey-ksm/aeads)
--reqtimeout num
number of seconds before a request times out (default: 5)
--pid-file fn
write process id of server to this file
BUGS
Report python-pyhsm/yhsm-yubikey-ksm bugs in the issue tracker <https://github.com/Yubico/python-pyhsm/issues/>
SEE ALSO
The python-yubico home page <https://github.com/Yubico/python-pyhsm/>
YubiHSMs can be obtained from Yubico <http://www.yubico.com/>.
python-pyhsm December 2011 yhsm-yubikey-ksm(1)