Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

directory() 1

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I am puzzled.

Consider this scenario: OS WIN(10)

lcDirectory = C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses

? lcDirectory returns .F.

md (m.lcDirectory)
returns error "A susidary of C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses already exists"

cd C:\users
cd koenp
cd appdata
cd roaming
cd myroamingfiles returns "Invalid path or file name"

What is going on here?

how can I check if a directory roamingclasses exists and if it does how can I find which files it contains?

Regards,

Koen

 
Code:
LOCAL Dir AS String

m.Dir = INPUTBOX("Enter a directory name...")

IF DIRECTORY(m.Dir, 1)
	IF !DIRECTORY(m.Dir)
		MESSAGEBOX(m.Dir + " exists but you don't have enough permissions to access it...")
	ELSE
		MESSAGEBOX(m.Dir + " exists and you have [at least some] access to it...")
	ENDIF
ELSE
	MESSAGEBOX(m.Dir + " does not exist...")
ENDIF
 
Hi,

Code:
lcDirectory = "C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses"
IF DIRECTORY(m.Dir, 1)
md (m.lcDirectory)
error:  "A susidary of C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses already exists"
endif

I cannot make lcDirectory!

Kindly assist.

Regards,
Koen
 
IMHO you should never ever use roaming directories for your apps, or in program files (x86)
 
Dan,
Could be possible, the variable getenv("Appdata") returns this directory.
Anyway how would you explain that
Code:
lcDirectory = C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses
? lcDirectory returns .F.
and
Code:
md (m.lcDirectory)
error:  "A subsidary of C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses already exists"
Regards,
Koen
 
Koen

It is all functioning as it should. If a call to DIRECTORY() returns .T., then the folder exists. If the folder exists, you can't create it. The second argument in the [tt]DIRECTORY(m.Dir[highlight #FCE94F], 1[/highlight])[/tt] function assures that the check for the directory will include all folders, no matter their attributes.

Did you run the code I posted, and checked on [tt]C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses[/tt]? It should output

C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses exists but you don't have enough permissions to access it...
 
Hi Atlopes,

Yes, I did run your code and it returns a .F.,
than I enter a

Code:
md C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses
which returns error:
"A susidary of C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses already exists"

question: how can I create directory C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses and if it does exist make use of it?

Regards,
Koen

 
Koen, you said you executed
Code:
lcDirectory = C:\users\koenp\appdata\roaming\myroamingfiles\roamingclasses
? lcDirectory returns .F.

1. This would error on the first line, as you forgot the string delimiters
2. This indicates you did not execute DIRECTORY(lcDirectory,1)

Are you sure you're really following atlopes advices here?
Besides that, I can see the directory without the special flag 1, but I'm on a standalone PC client without a domain or workgroup. Your mileage can vary, if the client is on a domain, you may not have permission to write into the roaming profile by group policies, for example.

Bye, Olaf.

 
Koen

The code I posted does not return anything. It just pops up a message box, depending on the circumstances of a particular folder.

The first call of the [tt]DIRECTORY()[/tt] function has the flag set to 1. This means that it tries to locate the directory no matter what its attributes are. In the case of the directory you're testing, it should return .T.

The second call of the [tt]DIRECTORY()[/tt] function, in the inner IF, has no flag set (the same way that you were using the function in the first place). Now, if the folder is either hidden or a system folder, it will return .F., meaning that although it exists, you don't have access to it.

As Olaf pointed out, system policies may interfere in the process, but I think that the call with nFlags = 1 works in the same way for folders to which you don't have access due to some policy constraint.
 
Appdata is a hidden directory, foxpro cannot see hidden directories.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi,

It seems I have posted code here to hastly, without quotes a.s.o., although they were present in my testing.
After more and more testing I found the answer to my question / error. You cannot create a directory with a subdirectory with the MD command, so in this case:

Code:
MD "C:\users\koenp\appdata\roaming\myroamingfiles"
MD "C:\users\koenp\appdata\roaming\myroamingfiles\myroamingclasses"
works.

Regards,
Koen
 
Mike, I know and see so in Windows Explorer, still VFP can see it, there must be some explanation and I think there is more to it than the merely hidden status making it hidden or not.
seehiddendir_b5lg6d.png


I know DIRECTORY(dir,1) and use it, whenever I want to ensure I see the directory. I also can confirm the directory is hidden by the system, in Windows Explorer I only see it faded when allowing to see hidden folders. Still it is not necessary to do Directory(y,1) in my case. Just for sake of completeness: [tt]? DIRECTORY(GETENV("Appdata"),1)[/tt] of course also shows .T.

Also, if I just add an arbitrary new folder and set it hidden, I can only see it with Directory(x,1), so my VP also isn't buggy.

That alone tells you there can be different situations about this, and when differences in visibility beyond the hidden attribute exist, then there might be some dependency also about the ability to write to a directory or not. If it's not permissions/security of the folder it must be group policies.

Bye, Olaf.
 
Appdata is a hidden directory, foxpro cannot see hidden directories.

Isn't that why Atlopes said to pass 1 as the second parameter to DIRECTORY()?

VFP Help for DIRECTORY() said:
DIRECTORY( ) returns True (.T.) if the directory exists, regardless of its attributes. Setting nFlags to 1 allows you to check for hidden or system files.

I believe it also applies to the FILE() function.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
[tt]MD[/tt] can create a tree of folders in a single command, but that will depend on its location.

Code:
MD (ADDBS("c:\temp") + "tek-tips\koen\it\works")  && this works
MD (ADDBS(SYS(2023)) + "tek-tips\koen\it\works") && this [probably] won't, in a W10 machine
 
Mike (Lewis). Sure, that's why Mike (Gagnon) said so, but also most probably because he doubted I can (let my VFP) see GETENV("Appdata") without needing that flag.

The problem not being able to create directories or write files into them must be elsewhere, I can also do both these things without restrictions.

Bye, Olaf.
 
Hi Atlopes,

Code:
MD (ADDBS(SYS(2023)) + "tek-tips\koen\it\works")
errors on my Win(10)

however if i do it in two shifts, it works.

P.S. It is not a matter of hidden directories which cannot be seen, it is a matter of creating more than one directory ( a directory with a sub-directory) in Getenv("APPDATA")

Regards,

Koen
 
Ah, that. I see that work and not work on conditions I don't know.

I made a recursive makedir function for that, but I try with the full directory and skip down in excpetion cases, then after the recursive call retry.

Code:
recursivemkdir(Addbs(GetEnv("Appdata"))+"level1\level2\level3\level4")

Function recursivemkdir(tcDir)
   Local llSuccess
   If Empty(tcDir)
      Return .F.
   Endif

   ? "try to make "+tcDir
   Try
      Md (tcDir)
      llSuccess = .T.
      ? "created "+tcDir
   Catch
      If recursivemkdir(Justpath(tcDir))
         Try
            Md (tcDir)
            llSuccess = .T.
            ? "created "+tcDir
         Catch
            * llSuccess still .F. from Local declaration
         Endtry
      Endif
   Endtry

   Return llSuccess
Endfunc

Bye, Olaf.
 
Olaf,

Your recursivemkdir works fine on my WIN(10) will keep it my basefunctions.
Thanks,

Regards,

Koen
 
Fine, just notice it could be made shorter, perhaps, but I also like the feature you will get to the max recursion trying to create a directory o a non existant drive, as JUSTPATH("T:\") = "T:\",so the check for EMPTY(tcDir) isn't quite helpful, as I now realized. It was there to detect the case you simply are not having the permission to create a directory somewhere. You can stop with RETURN .F. , if Directory(tcDir,1).

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top