Aug-27-2020, 09:10 PM
I'm trying to identify a file within a directory by removing list items containing an unwanted substring. When the script finishes running, list2 only contains 'test.test1-test-sample.mp4' when it's expected to contain 'test.test-test.mp4' Any help with where my mistake is would be greatly appreciated.
File's in directory: test.test-test.mp4 (intended target file), test.test1-test-sample.mp4, test.test2-test-Sample.mp4
This is not the entire script, just the relevant part. Please ignore the irrelevant imports.
File's in directory: test.test-test.mp4 (intended target file), test.test1-test-sample.mp4, test.test2-test-Sample.mp4
This is not the entire script, just the relevant part. Please ignore the irrelevant imports.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import tmdbsimple as tmdb import requests import locale import os import subprocess import shlex import json tmdb.API_KEY = '' api_key = '' user_input = input ( "Enter a video file location: " ) dest = input ( "Enter a destination directory: " ) list1 = [] list2 = [] if os.path.isfile(user_input): list1.append(os.path.basename(user_input)) base1 = os.path.splitext(list1[ 0 ]) basename = base1[ 0 ] else : list1.append(os.path.basename(user_input)) basename = list1[ 0 ] for file in os.scandir(user_input): if file .name.endswith(( '.mp4' , '.mkv' , '.avi' )): list2.append( file .name) for j in list2: if "-sample" or "-Sample" in j: list2.remove(j) #target_file = os.path.join(user_input, list2[0]) #print(list1) print (list2) #print(target_file) |