Page 1 of 1

Deleting File Suffix

Posted: Thu Apr 12, 2012 3:03 pm
by KommBI
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

Re: Deleting File Suffix

Posted: Thu Apr 12, 2012 5:25 pm
by mwieder
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

Re: Deleting File Suffix

Posted: Thu Apr 12, 2012 5:34 pm
by Klaus
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

Re: Deleting File Suffix

Posted: Fri Apr 13, 2012 11:03 am
by KommBI
thank u guys for answering! gong to try it out after work!
going to keep u up 2 date!

Re: Deleting File Suffix

Posted: Wed Apr 18, 2012 8:15 am
by KommBI
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

Re: Deleting File Suffix

Posted: Wed Apr 18, 2012 8:23 am
by KommBI
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

Re: Deleting File Suffix

Posted: Wed Apr 18, 2012 11:44 am
by Klaus
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

Re: Deleting File Suffix

Posted: Wed May 23, 2012 10:27 am
by KommBI
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

Re: Deleting File Suffix

Posted: Wed May 23, 2012 10:38 am
by Dixie
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

Re: Deleting File Suffix

Posted: Wed May 23, 2012 10:48 am
by KommBI
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