Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################################
- #####Grab randomly data from folder#####
- ########################################
- #0. Import variables
- #0. Import links
- #1. Declare variables
- #2. Create "Shuffled" folder
- #3. Read folder files - place into list
- #4. If too many files wanted, exit
- #5. Declare empty random number list
- #6. Loop for evey element in the given number of shuffled files
- #7. Generate random number between 0 and end of list
- #8. If the element exists, try again and find a new one
- #9. If new random number generated, grab file with this number and copy to Shuffled folder
- #0. Import variables
- import os
- import glob
- import random
- from sys import exit
- #0. Import links
- source_folder = "/Users/cristianpogan/Downloads/Test-comparatie-frames/outputlit2/No-Bin-24-Apr/"
- destination_folder = f"{source_folder}Shuffled/"
- #1. Declare variables
- wanted_files = 20
- #2. Create "Shuffled" folder
- os.system(f"mkdir {destination_folder}")
- #3. Read folder files - place into list
- all_files = glob.glob(f"{source_folder}*")
- print("list size: ", len(all_files))
- #4. If too many files wanted, exit
- if wanted_files > len(all_files):
- print("Cannot grab more than the number of files in folder")
- exit()
- for video in all_files:
- print(video)
- #5. Declare empty random number list
- rand_list = []
- #6. Loop for evey element in the given number of shuffled files
- for file in range(wanted_files):
- #7. Generate random number between 0 and end of list
- rand = random.randint(0,len(all_files))
- print(rand)
- #8. If the element exists, try again and find a new one
- if (rand in rand_list):
- print ("Element Exists")
- file = file - 1
- #Otherwise, it will shorten the loop with the elements already in the rand_list
- else:
- #9. If new random number generated, grab file with this number and copy to Shuffled folder
- print(f"Number {rand} not in list. Appending")
- rand_list.append(rand)
- print(f"Grabbing and copying element {all_files[file]}")
- print("to ")
- print(destination_folder)
- os.system(f"cp {all_files[file]} {destination_folder}")
- print("List of random files: ")
- print(rand_list)
- ########################################
- #####Grab randomly data from folder#####
- ########################################
- #0. Import variables
- #0. Import links
- #1. Declare variables
- #2. Create "Shuffled" folder
- #3. Read folder files - place into list
- #4. If too many files wanted, exit
- #5. Declare empty random number list
- #6. Loop for evey element in the given number of shuffled files
- #7. Generate random number between 0 and end of list
- #8. If the element exists, try again and find a new one
- #9. If new random number generated, grab file with this number and copy to Shuffled folder
- #0. Import variables
- import os
- import glob
- import random
- from sys import exit
- #0. Import links
- source_folder = "/Users/cristianpogan/Downloads/Test-comparatie-frames/outputlit2/No-Bin-24-Apr/"
- destination_folder = f"{source_folder}Shuffled/"
- #1. Declare variables
- wanted_files = 20
- #2. Create "Shuffled" folder
- os.system(f"mkdir {destination_folder}")
- #3. Read folder files - place into list
- all_files = glob.glob(f"{source_folder}*")
- print("list size: ", len(all_files))
- #4. If too many files wanted, exit
- if wanted_files > len(all_files):
- print("Cannot grab more than the number of files in folder")
- exit()
- for video in all_files:
- print(video)
- #5. Declare empty random number list
- rand_list = []
- #6. Loop for evey element in the given number of shuffled files
- for file in range(wanted_files):
- #7. Generate random number between 0 and end of list
- rand = random.randint(0,len(all_files))
- print(rand)
- #8. If the element exists, try again and find a new one
- if (rand in rand_list):
- print ("Element Exists")
- file = file - 1
- #Otherwise, it will shorten the loop with the elements already in the rand_list
- else:
- #9. If new random number generated, grab file with this number and copy to Shuffled folder
- print(f"Number {rand} not in list. Appending")
- rand_list.append(rand)
- print(f"Grabbing and copying element {all_files[file]}")
- print("to ")
- print(destination_folder)
- os.system(f"cp {all_files[file]} {destination_folder}")
- print("List of random files: ")
- print(rand_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement