How to do a search for a directory or file runing on Windows

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

How to do a search for a directory or file runing on Windows

Post by Subas » Thu Jul 11, 2013 5:22 am

Dear Friends.

i am not sure how to go about this as i have search the forum but did not find any examples.

Basically, the users keys in the date in this format YYYY-MM-DD and the stack will search in a particular path pre-defined in the search button. the pre-define directory will be \\10.2.260.2\messages\

In the message folders there will be many folders with the date as pre the above date format. The search stack should display to the user that particular folder. The user will then click on that folder and read the content which fill have many text files in it.

Could the LIVEcode friends help.

Thank You
Subas

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: How to do a search for a directory or file runing on Win

Post by Janschenkel » Thu Jul 11, 2013 8:23 am

Hi Subas,

You can set the 'defaultFolder' global property to the actual directory where the files are, and then use the 'files' function to get a list of the files this directory contains. Then you can read each of those files individually and apply your search algorithm.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Thu Jul 11, 2013 9:07 am

Dear Jan,

Thanks for the information.

Actually the search of the directory is what i need. Example: the users keys in on the 1st text field <ddmmyy> and a 2nd field the user keys in <AF001>. The system will start the search and goes to the initial default path \\10.2.260.2\messages\ and then look for the folder called <ddmmyy> in the message folder. Once the system finds it it will then take the 2nd field which is <AF001> that the users had keyed in an then display the files in that directory folder.

Could you please help on how to do this.

Thanks

Best Regards
Subas

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: How to do a search for a directory or file runing on Win

Post by shaosean » Thu Jul 11, 2013 11:26 am

Code: Select all

set the defaultFolder to ("\\10.2.260.2\messages\" + the text of field "firstField" + "\" + the text of field "secondField")
set the text of field "listOfFiles" to (the files)

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Thu Jul 11, 2013 3:55 pm

Dear shaosean

After trying the code out I get the below error:-

button "Button": execution error at line 2 (Operators +: error in left operand), char 30

could you help please.

Thanks

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: How to do a search for a directory or file runing on Win

Post by Janschenkel » Thu Jul 11, 2013 7:57 pm

I guess Shao Sean got some languages mixed up :-) LiveCode uses an ampersand to concatenate strings.

Code: Select all

set the defaultFolder to ("\\10.2.260.2\messages\" & the text of field "firstField" & "\" & the text of field "secondField")
set the text of field "listOfFiles" to (the files)
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: How to do a search for a directory or file runing on Win

Post by shaosean » Thu Jul 11, 2013 8:37 pm

yeah, using more than one language i sometimes get things mixed up ;-)

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Fri Jul 12, 2013 1:02 am

dear Janschenkel and shaosean

the code work perfectly. thank you

just one question can live code read the names of directories and pass those name to a drop down list so the user can select the appropriate directory? Also if there are changes made on the directory the system can then notify the user that there was a new directory?

Thanks

Best Regards
Subas

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: How to do a search for a directory or file runing on Win

Post by shaosean » Fri Jul 12, 2013 5:52 am

that's actually two questions ;-)

instead of "the files" use "the folders".. the engine does not support the file system change notifications, but (could you see this coming? ;-) ) you could always write an external to do it..

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Fri Jul 12, 2013 10:43 am

Dear shaosean.

Thank you I will try this out tonight. have a nice day ahead.

Best Regards
Subas

Klaus
Posts: 11103
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to do a search for a directory or file runing on Win

Post by Klaus » Fri Jul 12, 2013 11:45 am

Hi Subas,
Subas wrote: Also if there are changes made on the directory the system can then notify the user that there was a new directory?
no need for this, you can dynamically fill that button "on mousedown" or "on mouseenter", so it is always up-to-date :-)

Hint:
Livecode uses the UNIX pathdelimiter SLASH / internally, sou you should use them in your pathnames, EVEN if this is currently working ;-)
...
set the Folder to ("//10.2.260.2/messages/" & the text of field "firstField" & "/" & the text of field "secondField")
...

By the way, does this really work:
...
set the Folder to "//10.2.260.2/messages/"
...
? 8-)

And not to forget my eternal hint to this wonderful learning resource:
http://www.hyperactivesw.com/revscriptc ... ences.html :-D


Best

Klaus

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Sat Jul 13, 2013 2:08 am

Hi Klaus.

Good to hear from you. About your question of it the ip path actually works, yes it does seem to work. I am on a vpn access and the only folder on that server is the message folder. I was able to get to that folder and display the necessary directories. Since you mention it I will re check this on Monday morning fully.

Also thanks for the hint on the Unix path. I will change it based on that as I have seen most example showing it that way.

Also could you point me to the right direction for the "you can dynamically fill that button "on mousedown" or "on mouseenter", so it is always up-to-date" procedures. This is what I actually have in mind.

Thanks for the help and good to hear from you again.

Best Regards
Subas

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: How to do a search for a directory or file runing on Win

Post by Subas » Sun Jul 14, 2013 7:25 am

Hi Friends

Can some please help. I am not getting all my files shown on Field 3 below.

Code: Select all

on mouseUp
   
   put empty into button "Option Menu1" -- Clear everything on Option Menu 1
   
   set the defaultFolder to ("C:\Users\main\Desktop\live\" & the text of field "Field1" & "\" & the text of field "Field2") --Users keys in the 1st and 2nd Folder
   
   put the folders into theNewList --System reads the files in the 2nd Folder
   
repeat with count = 1 to the number of items of theNewList
   put item count of theNewList & cr after button "Option Menu1" --i get my folders dispalyed on the drop down list. User select from The Option Menu 1
   set "Option Menu1" of field "Field3" to (the files) --when user select the folder from Option Menu1 the files should display on Field3
end repeat

end mouseUp
 

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: How to do a search for a directory or file runing on Win

Post by shaosean » Sun Jul 14, 2013 7:44 am

Code: Select all

on mouseUp
   put empty into button "Option Menu1" -- Clear everything on Option Menu 1
   set the defaultFolder to ("C:\Users\main\Desktop\live\" & the text of field "Field1" & "\" & the text of field "Field2") --Users keys in the 1st and 2nd Folder
   put the folders into theNewList --System reads the files in the 2nd Folder

-- this is where the issues are   
repeat with count = 1 to the number of items of theNewList
   put item count of theNewList & cr after button "Option Menu1" --i get my folders dispalyed on the drop down list. User select from The Option Menu 1
   set "Option Menu1" of field "Field3" to (the files) --when user select the folder from Option Menu1 the files should display on Field3
end repeat
end mouseUp
Because you are doing the set in a repeat loop, each time it passes through, you are overwriting the last data set.. also, set "Option Menu1" of field "Field3" to (the files) is actually putting the files into a custom property "Option Menu1" of field "Field3"

Code: Select all

   put the folders into theNewList --System reads the files in the 2nd Folder
This actually puts the folders, not the files (as your comment states)


This code is in a button somewhere, or perhaps a use a different handler

Code: Select all

on mouseUp
  set the defaultFolder to ("C:\Users\main\Desktop\live\" & the text of field "Field1" & "\" & the text of field "Field2") --Users keys in the 1st and 2nd Folder
  set the text of button "Option Menu1" to (the folders)
end mouseUp
This is the code you need in the option menu

Code: Select all

on menuPick pChosenItem
  set the defaultFolder to (the defaultFolder & SLASH & pChosenItem)
  set the text of field "Field3" to (the files)
end menuPick
If you need someone to look at your code, I am available for a TeamViewer session and can help you out if you are so inclined..

Klaus
Posts: 11103
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to do a search for a directory or file runing on Win

Post by Klaus » Sun Jul 14, 2013 12:28 pm

Hi Subas,

as Mark said :-)

Hints:
1. "the files" and "the folders" return a CR delimited list, so this is not very clever:
...
put the folders into theNewList --System reads the files in the 2nd Folder
repeat with count = 1 to the number of items of theNewList
...
There is only ONE item (itemdelimiter is COMMA by default) in theNewList!
It would be a good idea to take a look at the terms in the dictionary if in doubt or if you get unexspected results! 8-)
I still do this after almost 15 years of working with Livecode, this is not a shame!

2. About dynamcially filling the button with folder content.
I would create a little function in the stackscript, that will return the files or the folders from a give folder,
so I can use this everwhere I need it like this:

Code: Select all

## 2 parameters:
## 1. the folder from where you want to get the content from
## 2. to make it a bit more useful we can supply "files" or "folders" as the second parameter
## so we can have the files OR the folders with the same function!

function GetFolderContent tFolder,FilesOrFolders
  ## Note previous directory and RESET this at the end!
  ## This is good programming style ;-)
  put the folder into tOldDir
  set the folder to tFolder
  if FilesOrFolders = "files" then
    put the files into tretValue
  else
    put the folders into tRetValue
  end if
  
  ## Reset directory!
  set the folder to tOldDir
  return tRetValue
end GetFolderContent
Now you can add this to the script of your "option" button:

Code: Select all

on mouseenter
  put ("C:/any valid folder path/here/" & the text of field "Field1" & "/" & the text of field "Field2") into tFolder
  put GetFolderContent(tFolder,"folders") into me
end mouseenter
Et voila, all available folders in menu, dynamically and up-to-data as possible :-)


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”