Unable to create validation data out of training image folders

I have been trying to create validation data folder out of the training folder , in the same way prateek bhaiya told in this lecture, but it gives file not found error, to overcome that issue in end i introduces another condition of , if the path not present then os.makedirs(path), it however successfully creates the validation data , but each image file if further present into another directory having same name as the image file name.I ma been working to resolve this issue for quite a long time now, plz if you can check the problem in my code. U can run my code having on google colab, it also contains the link to the dataset for which i am trying to make the validation dataset.
Code link:https://colab.research.google.com/drive/159sE8S9b76pdzXUCw4_IrW8QaDQDpit7?usp=sharing

hey @saksham_thukral,
kindly have a view at this code file . I have updated the same code file of yours.
Changes i have made is,
you wrote code line as
if not p :
then something

but you need to write as :
if not os.path.exists§ as p is something in memory and the code see it as not none.

I hope this might clear your doubt .