Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract files from a folder?
#1
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
#2
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
Code:
Copy      Help
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
#3
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
#4
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
#5
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
#6
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
#7
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


Forum Jump:


Users browsing this thread: 1 Guest(s)