Posts: 17
Threads: 7
Joined: Aug 2012
Hi,
I have n files in a folder, they are named by number such as: 1.jpg, 2.jpg, 3.jpg, 4.jpg and so on, for example, until 30.jpg.
I would like to extract into a new folder files in increments of 3, such as 1.jpg, 4.jpg, 7.jpg, 10.jpg, and so on.
I wrote the script below:
int i
ARRAY(str) a
GetFilesInFolder a "$Desktop$\I1\" ""
a.sort(8)
for i 0 a.len
,str s1=a[i]
,out s1 ;;ORIGIN FILES
,str s2=F"C:\Users\emers\Desktop\I2\{i+1}.jpg"
,out s2 ;;DESTINATION FOLDER
, ren s1 s2
but that would move ALL the files to folder I2.
Could someone tell how this works?
Thank you
Emerson
Posts: 1,338
Threads: 61
Joined: Jul 2006
07-31-2019, 02:01 AM
(This post was last modified: 07-31-2019, 09:41 AM by Kevin.)
this is what your after
you should used mkdir to make sure the new folder is created first incase it is not already.
the for loop just needs to start at 0 and increase by 3 each time.
since your just straight moving files there is no need to rename the files.
see code below
str dest="$Desktop$\I2\" ;;; this is the destination folder name
if(!FileExists("$desktop$\I2" 1)) ;; if folder doesnt exist
,mkdir dest
int i
ARRAY(str) a
GetFilesInFolder a "$Desktop$\I1\" ""
a.sort(8)
for i 0 a.len 3
,ren a[i] dest
Posts: 17
Threads: 7
Joined: Aug 2012
Hi Kevin, thank you so much for helping, your script works.
Brief note:
I had to change the for loop to start at 0.
If the loop starts at 1, the file start moving from 2.jpg, 5.jpg, 8.jpg, and so on.
If the loop starts at 0, the file start moving from 1.jpg, 4.jpg, 7.jpg, and so on, as desired.
It was a great help, thank you again
Emerson
Posts: 17
Threads: 7
Joined: Aug 2012
Hi Kevin,
I just tried again, without any change in your code, and the situation that I described continues.
Did you try to
,out[i]
and
,out a[i]
inside the loop?
if you do so, then you will understand what is happening
Thank you anyways
Emerson
Posts: 1,338
Threads: 61
Joined: Jul 2006
07-31-2019, 09:16 AM
(This post was last modified: 07-31-2019, 09:18 AM by Kevin.)
i see what the difference is. My test folder had files that started at 0.jpg
but in your case the files start at 1.jpg so starting the loop on 0 is correct. Half asleep code fixed above
Posts: 17
Threads: 7
Joined: Aug 2012
Hi Kevin,
never mind, it's a small technical detail. Your script does the job correct.
Thank you again for your help
Have a great night
Emerson
Posts: 64
Threads: 19
Joined: Nov 2012
Hi this was a good question and a super answer. It is good to see a way to use logic for the folder not existing. Thanks