Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to write a program that delete random image from folder in python code


What I have tried:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Posted
Updated 27-Jul-21 19:15pm
Comments
Richard MacCutchan 28-Jul-21 3:38am    
You program has (at least one) bugs.

1 solution

Without seeing your relevant code fragments we can't help with your syntax error at all - look at the line that the system is reporting a problem with and find which symbol is "odd".
Or post the actual code and we'll see if we can help.

But to answer the question "how to write a program that delete random image from folder in python code"...
1) Read a list of all the files in the folder: os.listdir — Python documentation[^] will do that.
2) Generate a random number between 0 and the number of files: random — Generate pseudo-random numbers — Python documentation[^]
3) Delete the file at that index: os.remove — Python documentation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900