Set defaultFolder BEFORE answer FOLDER

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
BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Set defaultFolder BEFORE answer FOLDER

Post by BarrySumpter » Mon May 09, 2011 8:27 am

Hi all,

Can't seem to work out how to

Set defaultFolder BEFORE answer FOLDER

Code: Select all

 local tFolder
 put field myFolder into tFolder
 Answer tFolder -- shows my default folder from myFolder field
 if tFolder is NOT blank then
    set the defaultFolder to tFolder - Not working like I want it to
 end if
answer folder "Please choose the folder you want to work with:"
Last edited by BarrySumpter on Mon May 09, 2011 1:27 pm, edited 2 times in total.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Dixie » Mon May 09, 2011 8:58 am

Barry...

See 'defaultFolder in the LiveCode dictionary.... and a snippet from the 'defaultFolder' entry... 'When a LiveCode application starts up, the defaultFolder initially contains whatever the working directory was at the time the application was launched. Typically this is the folder that the application resides in, however this is not always the case and shouldn't be relied on. It is best always to set the defaultFolder before using relative paths.'

So, for example... the script below will set the 'defaultFolder' to be wherever it is you have placed your stack on your hard drive.

Code: Select all

on preOpenStack
  set itemDel to "/"
  set the defaultfolder to item 1 to -2 of (the effective fileName of this stack)
end preOpenStack
be well

Dixie

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Klaus » Mon May 09, 2011 12:22 pm

Hi Barry,

1...if tFolder is NOT blank then...
"blank" is no reserved LiveCode keyword!
Use EMPTY instead:
...if tFolder is NOT EMPTY then...

2. You can use this syntax, no need to mess around with "the defaultfolder"
(I would NEVER rely on the defaultfolder!):
...
answer folder "Select folder:" with specialfolderpath("desktop")
...

OR like in your case:
...
set itemdel to TAB
put the effective filename of this stack ito tFolder
delete item -1 of tFolder
answer folder "Select folder:" with tFolder
...


Best

Klaus

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Dixie » Mon May 09, 2011 12:52 pm

Hi Klaus...
(I would NEVER rely on the defaultfolder!):
Why ever not ? Using the specialFoderPath is fine if you use one of the stock folder identifier's, but what if you wanted to default to 'Harry's Boojums" ?

be well

Dixie

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Klaus » Mon May 09, 2011 1:03 pm

Hi Dixie,

according to Murphys law the defaultfolder will change when you least exspect it! :D
Or just call it "personal preference based on long time experience" 8)

And when you can set the defaultfolder to "Harry*'s Boojums" then you know where to find this folder and can
do "regular" actions with that folder like using it as a parameter for "answer folder...".
Know what I mean?


Best

Klaus

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Set defaultFolder BEFORE answer FOLDER

Post by BarrySumpter » Mon May 09, 2011 2:04 pm

Brilliant!


Really starting to like LiveCode.
And geting used to the language structure.

Doco is a bit light though.


That specialFolderPath object is rich!
But still missing the application path.
(unless I missed it.)

Use the specialFolderPath function to place preferences in the Preferences folder, save files to the Documents folder, find out which files are installed in the System or Fonts folders, and so on.

Parameters:
The folderIdentifier is one of the following:

For Mac OS systems:
Desktop: The Desktop folder, where files or folders on the desktop are placed
System: The active System Folder
Apple: The Apple Menu Items folder inside the System Folder
Control: The Control Panels folder inside the System Folder
Extension: The Extensions folder inside the System Folder
Fonts: The Fonts folder inside the System Folder
Preferences: The Preferences folder inside the System Folder
Temporary: For storage of temporary files

For OS X systems:
Home: The current user's home directory (e.g. "/Users/Fred")
Desktop: The user's Desktop folder
System: The active System Folder
Fonts: The system Fonts folder
Preferences: The Preferences folder inside the user's Library folder
Temporary: For storage of temporary files
Documents: For user documents

For Mac OS and OS X systems, you can also specify a four-character special folder constant as the folderIdentifier. You can find a list of these constants on the Apple web site at <http://developer.apple.com/documentatio ... FolderType>.

Note: Some special folder constants are meaningful only on Mac OS or only on OS X but not both. Not all special folder constants work on all system versions.

For Windows systems:
Home : The current user's home directory (e.g. "C:/Documents and Settings/Fred")
Desktop: For icons on the desktop
System: For system components
Start: For items in the Start menu
Documents: For user documents
Fonts: For font storage
Temporary: For storage of temporary files

For Windows systems, you can also specify a CSIDL number that identifies a special folder. Some Commonly used CSIDL values are:
0x001a: The user application data folder (e.g. "C:/Documents and settings/Fred/Application Data")
0x0023: The "all users" application data folder (e.g. "C:/Documents and settings/all users/Application Data")
0x000d: The "My Music" folder
0x000e: The "My Videos" folder
0x0027: The "My Pictures" folder
0x000a: The recycle bin

You can find a complete list of available CDISL values on the Microsoft web site at <http://vbnet.mvps.org/index.html?code/b ... rsions.htm>.

Note: Not all CSIDL numbers work on all Windows versions, refer to the link above to find out more about CSIDLs.

For Unix systems:
Home: The current user's home directory (e.g. "/home/fred")
Desktop: The current user's desktop (e.g. "/home/fred/Desktop")
Temporary: For storage of temporary files (typically "/tmp")

Value:
The specialFolderPath function returns a folder name and location.

Comments:
If the folder is not found, the specialFolderPath function returns empty. If the folderIdentifier is either not supported on the current platform or doesn't exist on the current system, the result is set to "folder not found".
Some of the special folders you can specify with the specialFolderPath function need not have the standard names. (For example, the System Folder on Mac OS systems is not necessarily named "System Folder".) For this reason, the specialFolderPath function returns the full path to the folder, including the name of the folder.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

reflectedpixel
Posts: 6
Joined: Thu Jan 17, 2019 7:37 pm

Re: Set defaultFolder BEFORE answer FOLDER

Post by reflectedpixel » Fri Aug 02, 2019 4:10 pm

I'm trying to find the recycle bin on windows 10
SpecialFolderPath (0x000a)
doesn't return anything.

I'm just trying to recycle a file rather than obliterate it with the delete file command.


Appreciate any help. Thanks!
Jon

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Klaus » Fri Aug 02, 2019 7:20 pm

Hi Jon,

try: specialfolderpath("CSIDL_BITBUCKET")

Found here -> https://docs.microsoft.com/en-us/window ... hell/csidl
If that does not work, please do your own search, I am actually a Mac user. :D

Here another great resource for undocumented specialfolderpath names/codes: http://www.sonsothunder.com/devres/live ... ile010.htm
Some of them, like -> 0x000a obviously, may be deprecated, the docs are quite old.

Please create a new thread next time, noone except a bored admin like me, checks old threads. 8)


Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set defaultFolder BEFORE answer FOLDER

Post by bogs » Fri Aug 02, 2019 8:22 pm

Klaus wrote:
Fri Aug 02, 2019 7:20 pm
Please create a new thread next time, noone except a bored admin like me, checks old threads. 8)
<AHEM!> I beg your pardon Klaus!
{ Chiming in as a 'no one' from WAY way back :P }
Image

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Set defaultFolder BEFORE answer FOLDER

Post by SparkOut » Fri Aug 02, 2019 8:30 pm

noone except a bored admin like me, checks old threads.
Or me, not that I was either bored or an admin... I spent a little while investigating this, as in fact 0x0a is 10 in base 10 and as Ken Ray's page shows, no folder for CSIDL value 10 is applicable. specialFolderPath (10) will not return a value. This is understandable as the recycle bin is a virtual folder. CSIDL_BITBUCKET will not resolve to anything unless you hook directly into KNOWNFOLDERID calls. (Actually not even then.)

https://msdn.microsoft.com/en-us/window ... p/dd378457 says:

FOLDERID_RecycleBinFolder

GUID{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}
Display NameRecycle Bin
Folder TypeVIRTUAL
Default PathNot applicable—virtual folder
CSIDL EquivalentCSIDL_BITBUCKET
Legacy Display NameRecycle Bin
Legacy Default PathNot applicable—virtual folder

You won't ever actually get a path directly to the (virtual) Recycle Bin on Win 10. You cannot just move a file to the recycle bin "folder" and have it appear in the recycle bin listing.

You can do this (delete a file by moving it to the recycle bin) with a shell call to deleteJS.bat which you an obtain here: https://github.com/npocmaka/batch.scrip ... leteJS.bat

I was hoping to get a look at converting this to vbscript so that you can "do .. as" directly from LiveCode. But this does work as is on Windows 10.

Code: Select all

put quote & "<path to deleteJS.bat>" & quote && quote & "<path to the file to delete>" & quote into tCall
set the hideConsoleWindows to true
get shell (tCall)

If you just want to open the recycle bin on screen, you can:

Code: Select all

   put "explorer" && quote & "shell:RecycleBinFolder" & quote into tCmd
   set the hideConsoleWindows to true
   get shell(tCmd)

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

Re: Set defaultFolder BEFORE answer FOLDER

Post by Klaus » Fri Aug 02, 2019 8:49 pm

Damn, I knew this would not be easy.

Sorry folks, there are only two guys who check old threads, the bored admin and bogs.
Ah, and SparkOut, three guys... I'll come in again. (exit and exeunt)
:-D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set defaultFolder BEFORE answer FOLDER

Post by bogs » Fri Aug 02, 2019 9:37 pm

Klaus wrote:
Fri Aug 02, 2019 8:49 pm
Ah, and SparkOut, three guys...
Well, they *do* say things always happen in 3's... :D :D :D
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”