Deleting File Suffix

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Deleting File Suffix

Post by KommBI » Thu Apr 12, 2012 3:03 pm

Hello everybody!
I'm new to LiveCode, but I thinks its a great way to programm - that's why I already got the license!
Anyway I tryed to do this Lesson Creating a Video Library Application - with total success, but I dont want to have the file suffix within the List!
Can somebody may tell me how to get rid of the suffix?

Best regards & cheers

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Deleting File Suffix

Post by mwieder » Thu Apr 12, 2012 5:25 pm

In theGetFilesInFolder handler in the card script, insert the following instead of the final line (the "return theFiles" line):

Code: Select all

-- divide each line at the file specification
set the itemdelimiter to "."
-- now go through the list
repeat for each line tLine in theFiles
  -- grab everything up to the file type
  -- and put it into a new list
  put item 1 to -2 of tLine & cr after tFileNames
end repeat
-- now return the filtered list
return tFileNames

Klaus
Posts: 14196
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Deleting File Suffix

Post by Klaus » Thu Apr 12, 2012 5:34 pm

Hi KommBI,

welcome to the forum! :D

Another way, there are always a lot of ways to do something in LiveCode!, could be something like this:
...
## Acting behind the "curtains" will speed thing up a LOT!
lock screen
replace ".mp4" with EMPTY in fld "your list of video fles here"
## remove all other possible suffixes accordingly...
unlock screen
...
Or do the "replace" stuff with a variable before you put it into the field!

Please check these stacks to get a "feel" for this great app!
http://www.runrev.com/developers/lesson ... nferences/

Best

Klaus

KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Re: Deleting File Suffix

Post by KommBI » Fri Apr 13, 2012 11:03 am

thank u guys for answering! gong to try it out after work!
going to keep u up 2 date!

KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Re: Deleting File Suffix

Post by KommBI » Wed Apr 18, 2012 8:15 am

mwieder wrote:In theGetFilesInFolder handler in the card script, insert the following instead of the final line (the "return theFiles" line):

Code: Select all

-- divide each line at the file specification
set the itemdelimiter to "."
-- now go through the list
repeat for each line tLine in theFiles
  -- grab everything up to the file type
  -- and put it into a new list
  put item 1 to -2 of tLine & cr after tFileNames
end repeat
-- now return the filtered list
return tFileNames
hi mwieder!
thanks it looks very well, the suffix is gone BUT - actually when i return tFilesNames - don"t return theFiles (which actually are the video files) - so I have now a nice well fomrated list without the suffix, but the connection between list and video is gone!
do u know how to handle this?
cheers & thx

KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Re: Deleting File Suffix

Post by KommBI » Wed Apr 18, 2012 8:23 am

Klaus wrote:Hi KommBI,

welcome to the forum! :D

Another way, there are always a lot of ways to do something in LiveCode!, could be something like this:
...
## Acting behind the "curtains" will speed thing up a LOT!
lock screen
replace ".mp4" with EMPTY in fld "your list of video fles here"
## remove all other possible suffixes accordingly...
unlock screen
...
Or do the "replace" stuff with a variable before you put it into the field!

Please check these stacks to get a "feel" for this great app!


Best

Klaus
hey klaus!
thanks for your answer aswell, but it didn't work.
i put the loock screen ..... unlock screen into the function GetFilesInFolder but the suffix was still there. do I need to place the 3 lines at a different spot? EIDT: tryed different spots - same problem!
cheers

EDIT:
ok it works now, but i no have the same problem as with mwieders help. the list is well formated, but the connection between videos and list is gone!
hmm... would be cool if anyone of u guys can help me :)
chhers
oh yeah the code so far ...

Code: Select all

function GetFilesInFolder pFolder
   
   put the defaultfolder into therigDefaulFolder
   set the defaultFolder to pFolder
   put the files into theFiles
   set the defaultfolder to theOrigDefaultFolder
   filter theFiles without ".*"
   lock screen
   replace ".mov" with EMPTY in  theFiles
   unlock screen
   ##return theFiles
   ##set the itemdelimiter to "."
   ##repeat for each line tLine in  theFiles
      ##put item 1 to -2 of tLine & cr after tFileNames
      ##end repeat
   return  theFiles

Klaus
Posts: 14196
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Deleting File Suffix

Post by Klaus » Wed Apr 18, 2012 11:44 am

Hi KommBI,

"...but didn't work"? Could you elaborate?
I bet my script did what it was supposed to do :-)

Here some hints on your script:

Code: Select all

function GetFilesInFolder pFolder
   put the defaultfolder into therigDefaulFolder
   set the defaultFolder to pFolder
   put the files into theFiles
   set the defaultfolder to theOrigDefaultFolder
   filter theFiles without ".*"

   # Here you directly sort out all unwanted file suffixes:
   filter tFiles without "*.mov"
   ### etc...

  ## Now remove the suffix from the list:
  replace ".mov" with EMPTY in  theFiles

   ## lock screen is only necessary when you manipulate objects on the screen,
   ## like a fields content, but is not neccessary in a variable!

   ##lock screen
   ##replace ".mov" with EMPTY in  theFiles
   ##unlock screen
end GetFilesInFolder
Yes, now the files do not show their suffix anymore and your scripting needs to take care of that fact!

What do you use to actually play these video files, where the sufix is missing?
Please post (parts of) your code.


Best

Klaus

KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Re: Deleting File Suffix

Post by KommBI » Wed May 23, 2012 10:27 am

Hey Klaus!
Haven't been at work for quiet a while - but I'm back!
I figured out the problem - when i replace ".mov" with EMPTY then the file extention will be deleted aswell, because i return theFiles then without the suffix! - so livecode isn't able to find the videos anymore!

Code: Select all

preOpenCard
   ##Load the video list
   uiPopulateVideoList
## if ther is at least 1 video in the list then load the video
if the text of field "Video Menu" is not empty then
   set the hilitedline of field "Video Menu" to 1
   uiLoadSelectedVideo
end if
end preOpenCard

command uiPopulateVideoList
   ## Get list of videos files in Video folder
   put GetVideoFiles() into theFiles
   
   ## Assign the list of files to the list field
   set the text of field "Video Menu" to theFiles
end uiPopulateVideoList

function GetVideoFiles
   ## Get the path to the Video folder on disk
   put GetPathToFolder("Videos") into theFolder
   
   ## get list of files in the folder
    
   put GetFilesInFolder(theFolder) into theFiles

   ## Return list of Files
    
   return theFiles
end GetVideoFiles

function GetPathToFolder pFolderName
   
   ## Determine the location of this stack on disk
   put the filename of this stack into theFolder
   
   set the itemDelimiter to slash
   
   if the platform is "MacOS" then
      if theFolder contains ".app/Contents/MacOS" then
         delete item -3 to -1 of theFolder
      end if
   end if
   put pFolderName into the last item of theFolder
   return theFolder
end GetPathToFolder

function GetFilesInFolder pFolder
   
   put the defaultfolder into therigDefaulFolder
   set the defaultFolder to pFolder
   put the files into theFiles
   set the defaultfolder to theOrigDefaultFolder
   filter theFiles without ".*"
   replace "_" with " "  in theFiles
   replace "oe" with "ˆ" in theFiles
      replace "Oe" with "÷" in theFiles
      replace "ae" with "‰" in theFiles
      replace "Ae" with "ƒ" in theFiles
      replace "ue" with "¸" in theFiles
      replace "Ue" with "‹" in theFiles
   replace ".mov" with EMPTY in  theFiles 
## when i put the replace line in, no video can be played, because it doesn't find the source!
return  theFiles
end GetFilesInFolder

command uiLoadSelectedVideo
   put the selectedtext of field "Video Menu" into theVideoName
   put "Videos/" & theVideoName into theVideoFile
   set the filename of player "My Video" to theVideoFile
   set the currenttime of player "My Video" to 0
end uiLoadSelectedVideo
Yes, now the files do not show their suffix anymore and your scripting needs to take care of that fact!
How do I take care of that? I'm still pretty noob to liveCode...
What do you use to actually play these video files, where the sufix is missing?
I just put the Quicktime player field into the stack and it works perfect with the suffix!

Do you have any suggestions?
Cheers and thanks
Last edited by KommBI on Wed May 23, 2012 10:39 am, edited 1 time in total.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Deleting File Suffix

Post by Dixie » Wed May 23, 2012 10:38 am

You are deleting the suffix for presentation purposes ?
When you want to load the file just put the .mov suffix back onto the file name :-

Code: Select all

command uiLoadSelectedVideo
   put the selectedtext of field "Video Menu" into theVideoName
   put "Videos/" & theVideoName & ".mov" into theVideoFile
   set the filename of player "My Video" to theVideoFile
   set the currenttime of player "My Video" to 0
end uiLoadSelectedVideo
be well

Dixie

KommBI
Posts: 6
Joined: Thu Apr 12, 2012 2:59 pm

Re: Deleting File Suffix

Post by KommBI » Wed May 23, 2012 10:48 am

Dixie wrote:You are deleting the suffix for presentation purposes ?
When you want to load the file just put the .mov suffix back onto the file name :-

Code: Select all

command uiLoadSelectedVideo
   put the selectedtext of field "Video Menu" into theVideoName
   put "Videos/" & theVideoName & ".mov" into theVideoFile
   set the filename of player "My Video" to theVideoFile
   set the currenttime of player "My Video" to 0
end uiLoadSelectedVideo
be well

Dixie
voila it wors! thank dixie & thank you Klaus!!
no I can work on puttin a search button in ... : ) yeaha!
cheers

Post Reply