Page 1 of 1

moving files to different folders based on extension

Posted: Mon Feb 04, 2008 8:03 pm
by keyless
{this is for Windows}

For a program I am writing need to be able to seporate files in a folder into 2 different folders

In my program I have user select a folder and it put files into fList.

now I want to move certain files (based on user defined extensions) into one folder (call it Folder A) and others (based on second list of extensions) into another and ignor all other files.

The folders are already created.

There are fields for the user to put the file extentions into.
fld Graphics and fld Documents. The defaults for Graphics is: .txt, .doc
and the defaults for Documents is: .jpg, .gif, .png but the user can add more (seporating with comma).

I have tried several recursive methods to go through the files and move them to the the folders but nothing has worked so far. My main problem is I cant figure out how to pull the file path out of fList based on the extension.

much thanks in advance.

Posted: Tue Feb 05, 2008 2:04 am
by BvG
you most likely want to look at the itemdelimiter. Adjust the following for your needs

Code: Select all

put "c:/documents/" into thePath
repeat for each line theLine in fList
  set the itemdelimiter to "."
  if item -1 of theLine is among the lines of field "documents" then
    set the itemdelimiter to "/"
    rename file theLine to thePath & "/" & item -1 of theLine
  end if
end repeat

Posted: Tue Feb 05, 2008 4:36 am
by keyless
BvG wrote:you most likely want to look at the itemdelimiter. Adjust the following for your needs

Code: Select all

put "c:/documents/" into thePath
repeat for each line theLine in fList
  set the itemdelimiter to "."
  if item -1 of theLine is among the lines of field "documents" then
    set the itemdelimiter to "/"
    rename file theLine to thePath & "/" & item -1 of theLine
  end if
end repeat
Thank you so very much.

not sure what most of that code does, but

Code: Select all

repeat for each line theLine in fList
  set the itemdelimiter to "."
  if item -1 of theLine is among the lines of field "documents" then
  end if
end repeat
was exactly what I needed.