moving files to different folders based on extension

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

moving files to different folders based on extension

Post by keyless » Mon Feb 04, 2008 8:03 pm

{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.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue Feb 05, 2008 2:04 am

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
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Tue Feb 05, 2008 4:36 am

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.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”