Page 1 of 1

Just a few FileSystem-related questions

Posted: Sun Apr 13, 2008 7:56 am
by rozek
Hello!

Please excuse my ignorance, but I could not find any answers to the following questions by searching this forum or looking through the User's Guide/Transcript Reference:

How do I get the (disk) label and type of a given volume? Under Windows, "the volumes" yields a list of drive letters, but neither the drive's label nor the drive's type (removable, CD/ROM, network mapped drive etc.)

How do I find out whether a given "file" is actually a link (or "shortcut" under Win32) to the actual file? "the long files" does not contain that information

How Do I inspect a single file? "the long files" always yields a list for all files in "the defaultfolder", which then has to be "filter"ed or otherwise reduced. One of my clients has production folders containing > 40000 (yes, fourty thousands!) files (please, no complaints about this number: he will not change his running system aas that is too large and runs fine) With that many files loading a full list just to inspect a single file is really inefficient...is there any more direct way (or even s.th. like an "iterator" which avoids having to load all lines at once)?

Thanks in advance for any help!

Posted: Thu Apr 17, 2008 12:16 pm
by Mark
Hi Andreas,

Here is a possible solution for getting drive information:

Code: Select all

function drivesInfo
  if the platForm is "Win32" then
    put the volumes into myVolumes
    set the hideconsolewindows to true
    repeat for each line myDrive in myVolumes
      put shell("dir" && myDrive) into myInfo
      if myInfo contains "not ready" then next repeat
      put myDrive & tab & last word of line 1 of myInfo & tab & \
      last word of line 2 of myInfo & cr after myDrivesInfo
    end repeat
    return myDrivesInfo
  else
    return the volumes
  end if
end drivesInfo
On Windows, this function returns a table with in the columns the drive letter, the label and the serial number. I think we could have serial number on Mac OS X as well, but for now this function just returns one column with the drive names on Mac OS X. I haven't found a good solution for Linux (the volumes function is empty on Linux). Unfortunately, this function can be very slow if one has many drives. There might be a better shell command to do this.

To find out whether a file is actually a link, just check the last 4 letters of the file path:

if char -4 to -1 of theFilePath is ".lnk" then -- it is a shortcut

On Mac OS X, if you select an alias in an open file dialog, you get the referenced file rather than the location of the alias returned. If you somehow stumble into a path to an alias, you can check the last word of the file name. For example, if the path to the alias is

"/disk/folder/filename alias"

you can check the last word of the file path, which is "alias".

If you are still not sure, you can use the aliasReference function. If the value returned by the function is different, you are dealing with an alias. Otherwise, it is a file by itself.

What do you want to find out about individual files? Why do you think that loading an entire list of files is inefficient?

If you want to know whether a file exists, you can simply use this syntax:

Code: Select all

if there is a file myPathToFile then
Best,

Mark

Posted: Thu Apr 17, 2008 3:07 pm
by kotikoti
Hi Mark,
New to RR and just getting code and trying it out.
the posted code is failing on line

Code: Select all

put the volumes into myVolumes 
with a script error.

compiling at 3:06:32 PM
Type Chunk: can't create a variable with that name (explicitVariables?)
Object Button
Line put the volumes into myVolumes
Hint myVolumes


Help us to understand this please...

Posted: Thu Apr 17, 2008 3:16 pm
by Mark
Dear kotikoti,

Open Revolution's preferences window. Go to the Script Editor pane of this window. Make sure that "Variable Checking by Default" is turned off.

This should make the error go away.

Best,

Mark

Posted: Thu Apr 17, 2008 3:45 pm
by kotikoti
Hi Mark,
The error goes away but the function doesnt work

#example5
set the itemDelimiter to "/"
put the effective filename of this stack --into theFolder # 'effective' in case 'this stack' is a substack
--put item 1 to -2 of it into theFolder # Strip off filename
answer it titled "example5"

I have had to comment out the into theFolder as well as put item 1 to ..
when I remove the comments without the said setting I get error on apply, when I make the changes no error but the desired output can't be displayed.

Sorry for asking too much, but am enjoying this learning...

Posted: Thu Apr 17, 2008 4:56 pm
by Mark
Dear kotikoti,

Your script

Code: Select all

 #example5
set the itemDelimiter to "/"
put the effective filename of this stack --into theFolder # 'effective' in case 'this stack' is a substack
--put item 1 to -2 of it into theFolder # Strip off filename
answer it titled "example5" 
first puts the path to the stackfile into the message box and then displays the current contents of "it" in an answer dialog. What exactly are you trying to do? Does it have anything to do with the volumes function?

Best,

Mark

Posted: Thu Apr 17, 2008 5:57 pm
by kotikoti
Hi Mark,
I am trying o strip out the data from the path to get the filename only, but when I uncomment the "put" line

Code: Select all

put the effective filename of this stack into theFolder 
put item 1 to -2 of theFolder into theFolder 
answer theFolder titled "example5
I get the mentioned error, believe at the first line

Posted: Thu Apr 17, 2008 6:42 pm
by BvG
When you test, make sure that you are testing within a stack that you saved to the hard drive somewhere. A stack that is not saved will not have a filename. Also make sure to set the itemdelimiter, as the item 1 to -2 of a string that does not contain the itemdelimiter will be empty (most paths do not contain a comma, which is the default).

An example i tried in a quickly saved stack, that works fine:

Code: Select all

on mouseUp
  set the itemdelimiter to slash
  put the effective filename of this stack into theFolder 
  put item 1 to -2 of theFolder into theFolder 
  answer theFolder titled "example5"
end mouseUp

Posted: Thu Apr 17, 2008 6:48 pm
by kotikoti
Thanks Mark and BvG for working through this with me. A
new user gaining good grounding in RR appreciates your timely response.
Koti

Posted: Thu Apr 17, 2008 6:57 pm
by Mark
kotikoti wrote:Thanks Mark and BvG for working through this with me. A
new user gaining good grounding in RR appreciates your timely response.
Koti
Is it solved now?

Mark

Posted: Fri Apr 18, 2008 1:11 pm
by kotikoti
works fine. picked up this code from another topic, and I am reading on string operations to sprice the line as required.
Thanks again...

Code: Select all

  set the itemdelimiter to slash 
put the effective filename of this stack into theFolder 
answer theFolder titled "before" 
put item 1 to -2 of theFolder into theFolder 
answer theFolder titled "after" 

Posted: Wed Apr 23, 2008 5:50 pm
by rozek
Mark,

thank you very much for your effort!

I had hoped, that I could perform such basic operations as the examination of a file using "built-in" methods...

Thanks anyway for your help!