Ahmed Youssef avatar Ahmed Youssef committed 09fd8ad

.torrent files filter should be used with directories

Comments (0)

Files changed (1)

pytorrentrename.py

 	if nospaces:
 		new_torrent_path=new_torrent_path.replace(" ", "_")
 	os.rename(torrentpath, torrent_name)
+
+def filter_torrents(fileslist):
+	"""
+	filters files list <based on extension .torrent>
+	fileslist: list of files 
+	"""
+	_filter_func=lambda x : "torrent" in x
+	return filter(_filter_func, fileslist)
 	
 def rename_directory_of_torrentfiles(dirpath, nospaces=True):
 	"""
 	"""
 	os.chdir(dirpath)
 	dirlist=os.listdir(dirpath)
-	for f in dirlist:
+	torrent_files=filter_torrents(dirlist)
+	for f in torrent_files:
 		rename_torrentfile(f, nospaces)
-			
+	
 def console():
 	if len(sys.argv)>0:
 		#first check if the argv[1:] is a files or dirs list or exit()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.