So basically like the thread title says, I need to copy every 50th image from one folder to another.
I would write a Python script, but unfortunately I'm too stupid for that... And manually copying those images is not a solutions as well...
So, any ideas?
-
killkenny1 Too weird to live, too rare to die.
-
Have you looked at the various switches in Xcopy? I know it can copy files that have a date you specify and it can copy 'read only' files with the proper switch. So you could make every 50th a read only file then it will copy that one only. Check out the other switches here: http://pcsupport.about.com/od/commandlinereference/p/xcopy-command.htm
Maybe if you explained why you want to copy the 50th file, then someone can come up with a script to do it. As it stands now, your request seems a bit odd.killkenny1 likes this. -
Kaze No Tamashii Notebook Evangelist
maybe change every file's name into number in ascending order then write a script to copy file whose name is a multiple of 50?
-
killkenny1 Too weird to live, too rare to die.
But sure, if it will make easier for you and the others to understand I can explain the reason for my request.
I did some testing, and it involved high speed camera taking lots of pictures, so in the end I have more than 30000 (that's right, I said thirty thousand) files. It was decided that using every 50th image will be enough for evaluation purposes. But as you can see, with such high number of date going through them manually is not an option.
And to make things more interesting, they aren't labelled 1, 2, ..., n, although they are still in an ascending order.
I'll look into Xcopy. -
Well, I don't have a Python interpreter on hand at the moment, though this should be close to what you want to do in a Python script (I'm assuming you mean every 50th by timestamp):
Code:import os from shutil import copyfile def sortedListing(pathtodir): mtime = lambda f: os.stat(os.path.join(pathtodir, f)).st_mtime return list(sorted(os.listdir(pathtodir), key=mtime)) filesToCopy = sortedListing("C:\path\to\dir")[0::50] # Selects every 50th file by timestamp for file in filesToCopy: copyfile(file, "C:\path\to\copy\to")
killkenny1 likes this. -
killkenny1 Too weird to live, too rare to die.
I did a bit of Googling and ultimately went with a bit of different code.
Code:import os, shutil src_files = os.listdir('E:\\Desktop\\Cam') for file_name in src_files: if file_name.endswith('50.bmp'): full_file_name = os.path.join('E:\\Desktop\\Cam', file_name) if (os.path.isfile(full_file_name)): shutil.copy(full_file_name, 'E:\\Desktop\\Cam\\New folder')
I might try something more more later at work.
BTW, if anyone is interested, this is how file names look:
Obviously for testing purposes I only had a small number of images present in that folder. -
Glad it worked out for ya.
-
katalin_2003 NBR Spectre Super Moderator
The script from @Jarhead is more portable for your situation.
I would tweak that to your needs.custom90gt, toughasnails, ALLurGroceries and 2 others like this. -
Shutil.copy is also a fair bit slower than copyfile, though if it works for you then it works.
Not sure if the sorted listing can be faster. Still new to Python and I basically ripped that straight from StackOverflow.killkenny1 and katalin_2003 like this. -
killkenny1 Too weird to live, too rare to die.
Shutil.copy worked fine for my case.
But just in case, I have commented the code Jarhead has posted in the program
Copying every 50th file from one folder to another
Discussion in 'Windows OS and Software' started by killkenny1, Aug 26, 2016.