Python学习练习:批量移动文件
生活随笔
收集整理的這篇文章主要介紹了
Python学习练习:批量移动文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天想往MP3下點(diǎn)音樂,但是滿了,想把里面不喜歡的刪了,但是音樂都在各個(gè)文件夾下,于是,我希望所有的音樂文件可以移動(dòng)到一個(gè)層面,以供我按照音樂專輯的封面來挑選要?jiǎng)h哪個(gè),于是就想寫個(gè)程序來做一下整理,想想用我擅長的Java來寫吧,但是沒什么意思,想到一直想學(xué)Python,何不拿Python練練手呢?
于是:安裝環(huán)境:2.5,3.4,2.7,我有3個(gè)版本,在練習(xí)的時(shí)候發(fā)現(xiàn)有些語法問題,我猜可能是版本的問題,于是換了3個(gè)版本,最后用了最穩(wěn)定的2.7。IDE使用的是Eclipse。
通過查看簡單的Python語法說明:http://pythonprogramminglanguage.com/以及一個(gè)API文檔https://docs.python.org/2/library/index.html,勉勉強(qiáng)強(qiáng)的把這個(gè)程序?qū)懗鰜砹?#xff1a;
''' @author: Sahadev ''' import os import shutilpath = "H:\Music\CloudMusic"; listdir1 = os.listdir(path) i = len(listdir1) print i for j in range(i):print(listdir1[j])file = path + '\\' + listdir1[j]isdir = os.path.isdir(file)if isdir:childPath = os.listdir(file)len1 = len(childPath)for k in range(len1):result = file + '\\' + childPath[k]childFileName = path + '\\' + childPath[k]print childFileNameos.rename(result, childFileName)if len1 == 0:os.removedirs(file)剛開始寫的程序,貼出來也沒有什么注釋,可能代碼只有我自己知道了,嗯,就是個(gè)見證。
再貼上控制臺(tái)日志:
158 Wavves Waylon Jennings X-Ray Dog Yeasater Yellowman Zedd 上田雅美 天野正道,鈴木幸太,海田明里 宗次郎 小林啓樹 小見山優(yōu)子 山岡晃 川井憲次 本田晃弘 柴田徹也 植松伸夫 澤野弘之 石元丈晴 Alexey Omelchuk - The Farewell.mp3 Audio Machine - An Unfinished Life.mp3 Audio Machine - Breath and Life.mp3 Audio Machine - Danuvius.mp3 Audio Machine - Equinox (No Choir).mp3 Audio Machine - Shadowfall.mp3 Audio Machine - Sol Invictus.mp3 Audio Machine - The New Earth.mp3 Bill Brown,Mikael Sandgren - Generals Main Theme.mp3 Brand X Music - Eventide.mp3 Brian Reitzell - Ghost of the Past.mp3 Brian Tyler - Assassin's Creed IV Black Flag Main Theme.mp3 Brian Tyler - Falling Into A Dream.mp3 Brian Tyler - Mw3 End Credits.mp3 Brian Tyler - Need for Speed: The Run.mp3 Bryan Adams - Run Free.mp3 Chris Tilton - Mercenaries Main Theme.mp3 Dirk Reichardt - Weekend.mp3 Dreamtale - Intro: The Dawn.mp3 E.S. Posthumus - Nara.mp3 Elitsa Alexandrova - Assassin's Creed Rogue Main Theme.mp3 Epic Score - We Owe You Our Lives.mp3 Era - Prayer.mp3 Gerard Marino - God Of War Iii Overture.mp3 Glenn Stafford - Heart of the Swarm.mp3 Gothic Storm - Stand And Fight.mp3 Greg Edmonson - Nate's Theme 3.0.mp3 Gregorian - O Fortuna (Single Edit).mp3 Gustaf Grefberg - Mayhem Dressed in a Suit.mp3 Hans Zimmer - Antrozous.mp3 Hans Zimmer - Crysis 2 Intro - intro.mp3 Hans Zimmer - End Credits.mp3 Hans Zimmer - Opening Credits.mp3 Hans Zimmer - Rock House Jail.mp3 Hans Zimmer - The Enemy Of My Enemy Is My Friend.mp3 Hans Zimmer,Lorne Balfe - Jodie's Suite.mp3 Harry Gregson-Williams - Life.mp3 Harry Gregson-Williams - Path to Heaven.mp3 Health - Tears.mp3 Henry Jackman - First Class.mp3 Ian Livingstone - The Month Of Valiant Effort.mp3 Imagine Dragons - Warriors.mp3 Immediate Music - Dark Side Of Power.mp3 Immediate Music - Glory Seeker.mp3 Immediate Music - Serenata Immortale.mp3 Immediate Music - The Black Legend.mp3 Inon Zur - Main Title.mp3 Jack Wall - Adrenaline.mp3 Jai Paul - Jasmine.mp3 James Hannigan - Ra3 Theme - Soviet March.mp3 James Hannigan - To Save Humanity.mp3 Jamie Christopherson - Main Theme ~LOST PLANET~.mp3 Jason Graves - Convergence Delayed.mp3 Jeff van Dyck - Forever (ROME- TOTAL WAR).mp3 Jeremy Soule - Dragonborn (1).mp3 Jeremy Soule - Dragonborn.mp3 Jesper Kyd - Death Brings Hope.mp3 Jesper Kyd - Ezio's Family.mp3 Jesper Kyd - Hitman 2 Main Title.mp3 Jesper Kyd - Three Horns Valey Boom Boom Fight.mp3 Johan Skugge,Jukka Rintamaki - Battlefield 3 Main Theme.mp3 John Dreamer - End of My Journey.mp3 Joseph Trapanese - Introductions.mp3 Kevin McMullan - Noddinagushpa (Main Title).mp3 KOKIA - Believe in the Spirit.mp3 KOKIA - EXEC_COSMOFLIPS/.mp3 League of Legends - Challengers.mp3 League of Legends - Welcome to Planet Urf.mp3 London Philharmonic Orchestra - Legend of Zelda: Suite.mp3 Malcolm Kirby Jr. - Saints Row IV.mp3 Martin O'Donnell - Halo Theme Mjolnir Mix.mp3 Matt Uelmen - Wilderness.mp3 Mike Zarin - Welcome to 4th Echelon.mp3 Motoi Sakuraba - Velstadt the Royal Aegis.mp3 Neil Davidge - Arrival.mp3 Nick Arundel - Arkham City Main Theme.mp3 Noisia - Mundus Theme.mp3 Poets of the Fall - The Poet & The Muse.mp3 Ramin Djawadi - Deploy.mp3 Ramin Djawadi - Main Title.mp3 Ramin Djawadi - Pacific Rim.mp3 Russell Brower - And The Heavens Shall Tremble.mp3 Russell Brower - I Am Justice.mp3 Russell Brower - The Wandering Isle.mp3 Russell Brower - Wrath Of The Lich King (Main Title).mp3 Russell Brower,Neal Acree - Times Change.mp3 Sascha Dikiciyan - Alex Theme.mp3 Seo Jeong Min - Counter Strike Online.mp3 Soundtrack - Arthas, My Son (Cinematic Intro) - intro.mp3 Soundtrack - Baba Yet (Menu music).mp3 Soundtrack - Crysis 3 - New York Memories.mp3 Soundtrack - Hell March 3.mp3 Soundtrack - Main Theme.mp3 Soundtrack - Main Titles.mp3 Soundtrack - Menu Opening-DarkNightEnvoy.mp3 Soundtrack - Wings Of Liberty.mp3 Stephen Barton - Wallrunner.mp3 Steve Jablonsky - Armored Prayer.mp3 Steve Jablonsky - Forgotten Sands (Main Theme).mp3 Steven Burke - Hero's Theme.mp3 Thomas Bergersen - Empire of Angels.mp3 Thomas Bergersen - Homecoming.mp3 Tracy Bush - Main Title_Legends of Azeroth.mp3 Tracy Bush - Stormwind(City Theme).mp3 Two Steps From Hell - Blackheart.mp3 Two Steps From Hell - Dragon Rider74.mp3 Two Steps From Hell - Heart of Courage - Original.mp3 Two Steps From Hell - Strength Of A Thousand Men.mp3 Two Steps From Hell - Victory.mp3 V.A. - A Hero Unmasked.mp3 V.A. - Main Theme.mp3 V.A. - Monster Hunter 4.mp3 V.A. - ベヨネッタ戦闘態(tài)勢 A (EV03-7).mp3 Vangelis - Titans.mp3 Various Artists - hero select underscore loop.mp3 Various Artists - select intl.mp3 Wavves - Nine Is God.mp3 Waylon Jennings - I Ain't Living Long Like This.mp3 X-Ray Dog - String Tek.mp3 Yeasater - Don't Come Close.mp3 Yellowman - Nobody Move;Nobody Gets Hurt.mp3 Zedd - The Legend Of Zelda - Original Mix.mp3 上田雅美 - The Last Escape.mp3 天野正道,鈴木幸太,海田明里 - Onimusha 3 Opening.mp3 宗次郎 - 故鄉(xiāng)的原風(fēng)景.mp3 小林啓樹 - Zero.mp3 小見山優(yōu)子 - 英雄の証3(tri-)Version.mp3 山岡晃 - Theme of Laura.mp3 川井憲次 - 七劍戰(zhàn)歌.mp3 本田晃弘 - METAL GEAR SOLID PEACE WALKER Main Theme.mp3 柴田徹也 - The Time Has Come.mp3 植松伸夫 - Answers.mp3 澤野弘之 - Ace and Arms.mp3 澤野弘之 - CODENAMEZ.mp3 澤野弘之 - THEMEX.mp3 石元丈晴 - 世に仇なす者 (FFVII『片翼の天使』より).mp3 石元丈晴 - 我ら來たれり.mp3OK,Python也算是體驗(yàn)了一把了。
總結(jié)
以上是生活随笔為你收集整理的Python学习练习:批量移动文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 当知识图谱遇上推荐系统(总述和推荐)
- 下一篇: 【Java】网络编程