File or Directory
#1
Rre-posted and translated from http://www.beusergroup.de/ ( witrh permission from lelldorin.

ab - File or directory


Category: Applications
Published on Saturday, 11 July 2015 19:34
Written by Christian Albrecht
Hits: 13
How do I find out if I have a file or directory on a file panel or Dropzone must process?

My solution in this regard includes an IF query and a subroutine.

If statement:
Code:
Folder$=Quellvariable$

if(IfDirectory(Folder$))then
      is_an_directory=1
else
      is_an_directory=2
endif
print is_an_directoryy


Subroutine:

Code:
sub IfDirectory(filename$)
      return not system("test -d "+filename$)
end sub

To find out if I have to process a directory or file on a file panel or drop zone, I commend my path to the variable Folder $ and use the test command to check whether I have passed a directory in the variable.
If the check is positive, the number variable is_an_directory is set to 1 by the if statement. Is it not a directory, the value is set to 2.

Example: No matter what is passed, it will detect the file path

If statement:

Code:
if(IfDirectory(Quellvariable$)) then
      is_an_directory=1
      Folder$= Quellvariable$
else
      is_an_directory=2
      dim SplitFolderPath$(1)
            splitting = split(Quellvariable$, SplitFolderPath$(), "/")
            for i = 2 to splitting-1
                  Folder$=Folder$+"/"+SplitFolderPath$(i)
            next i
            print "folder:"+Folder$
endif


Subroutine:

Code:
sub IfDirectory(filename$)
      return not system("test -d "+filename$)
end sub


In this example, we are expanding this test and determine no matter what we ask for (file or directory) as the file path.

"Not" determined the test command list, the source variable over an array (SplitFolderPath $ ()) is cut into its individual parts. To do this, for each "/" mark is applied a new entry in the array.
After all array entries are reassembled, with the exception of the last entry.
Reply


Messages In This Thread
File or Directory - by bbjimmy - 07-15-2015, 10:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting