CreateDirectory() ?

Just starting out? Need help? Post your questions and find answers here.
Nonproductive
User
User
Posts: 17
Joined: Fri Apr 25, 2003 10:43 pm

CreateDirectory() ?

Post by Nonproductive »

I was creating a little app to set up a series of directories...the user would enter their folder names in a series of String Gadgets and then I thoguht I could just iterate through them and create each directory....
No matter how I try to do it the create directory command fails.
I even replaced it with a straight up CreateDirectory("C:\test\test") and it fails

What am I doing wrong?

(PB 3.81 - windows)

Code: Select all

      For XX = 2 To 7
      If Len(GetGadgetText(XX))>0
          FoldertoCreate$ = Dir_part$ + GetGadgetText(#Proj_Name) + "\" + GetGadgetText(XX)
          Result = CreateDirectory(FoldertoCreate$)
      EndIf
      Next
[/code]
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

?? The simple line

Code: Select all

Debug CreateDirectory("C:\temptestdeleteme")
does not work ?

Perhaps the directory already exists ? (Then 0 is returned)
Or you don't have the rights to write to that disk into the specified directory ?
%1>>1+1*1/1-1!1|1&1<<$1=1
Nonproductive
User
User
Posts: 17
Joined: Fri Apr 25, 2003 10:43 pm

Post by Nonproductive »

Just tried this:

Code: Select all

Debug CreateDirectory("C:\test\test")
Fails (returns 0)

BUT

Code: Select all

Debug CreateDirectory("C:\test\")
Works fine.

as does:

Code: Select all

Debug CreateDirectory("C:\test\test\")
Ah ha! you say - "just add the trailing '\'!"

nope... tacking + "\" onto the original concatentation code still yields failure when creating the directory.


I am on my personal machine at this point and absolutely have the proper rights and the folder(s) do nto already exist.

I'm baffled.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Iiiih. I got it.
You cannot create a subdirectory of a directory that doesn't exist !

This one here results in 0 1 1:

Code: Select all

Debug CreateDirectory("C:\test\test") 
Debug CreateDirectory("C:\test") 
Debug CreateDirectory("C:\test\test") 
Hum. That's not nice.
I cannot see a positive aspect in this behaviour - so I think this is something for the ToDo-List ?

It would be easier, if all non-existing parent-directories would be created with this function, too.

But here's a workaround:

Code: Select all

Procedure CreateDirectoryAll(dir.s)
  Protected result.l, dir_sub.s, dir_total.s, count.l
  
  count = 1
  dir_sub = StringField(dir, count, "\")
  dir_total = dir_sub + "\"
  
  While dir_sub <> ""
    result.l = CreateDirectory(dir_total)
    
    count + 1
    dir_sub = StringField(dir, count, "\")
    dir_total + dir_sub + "\"
  Wend
  ProcedureReturn result
EndProcedure

Debug CreateDirectoryAll("C:\test1\test2\test3"); there may be 0 or more '\' at the end
%1>>1+1*1/1-1!1|1&1<<$1=1
Nonproductive
User
User
Posts: 17
Joined: Fri Apr 25, 2003 10:43 pm

Post by Nonproductive »

That's IT!

I assumed that the "root" folder would be created...excellent catch!


Very much appreciate your help and quick responses! :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> You cannot create a subdirectory of a directory that doesn't exist

Actually, you can with an API command... try this:

Code: Select all

MakeSureDirectoryPathExists_("c:\123\456\789\")
:)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

hmmmm

Post by Fangbeast »

PB wrote:> You cannot create a subdirectory of a directory that doesn't exist

Actually, you can with an API command... try this:

Code: Select all

MakeSureDirectoryPathExists_("c:\123\456\789")
:)
This worked on my win xp box but when I call up my win32help file, I realise how old my reference file is (sigh).

Do you know how many platforms this works on?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
spongehammer
User
User
Posts: 84
Joined: Sat Jul 19, 2003 6:45 pm
Location: UK

Post by spongehammer »

Hi Fangbeast

this is from the SDK

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.
Header: Declared in Dbghelp.h.
Library: Use Dbghelp.lib.
I looked up 'paranoid' in the dictionary this morning.
It said, 'what do you want to know that for?'
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Ouch!

Post by Fangbeast »

spongehammer wrote:Hi Fangbeast

this is from the SDK

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.
Header: Declared in Dbghelp.h.
Library: Use Dbghelp.lib.
I guess I will have to grab an up to date SDK from somewhere then, fairly sure I don't have it lying around handy:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

Froggerprogger wrote:But here's a workaround:

Code: Select all

Procedure CreateDirectoryAll(dir.s)
nice!
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.

Hmm... on my Win 98 SE machine I have no files named dbghelp.* at
all, yet this API command works... so I'd say it doesn't require that DLL
at all. Strange. Fangles: I've got this API command in one of my apps
that is intended for all versions of Windows, so even though I can't
re-check it now, I assume it does work with all Windows because I
would have checked it for such before adding it to my app. ;)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Maybe so but...

Post by Fangbeast »

PB wrote:> So Fangles: It seems to work with Win 98 SE and up. I don't have my other PC to check it with other Windows versions, but I do have it in one of my apps, so I would have checked it before or I wouldn't be using it. ;)
Maybe so but, many of use beginnerish types (not you masters!!) are guilty of stuffing api's in our programs and not even checking they will work on their target audiences so I am now getting to be a cautious old bean in my old age and making notes:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

PB wrote:> Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.

Hmm... on my Win 98 SE machine I have no files named dbghelp.* at
all, yet this API command works... so I'd say it doesn't require that DLL
at all. Strange. Fangles: I've got this API command in one of my apps
that is intended for all versions of Windows, so even though I can't
re-check it now, I assume it does work with all Windows because I
would have checked it for such before adding it to my app. ;)
It works on my Win98SE too ; I think you only need IMAGEHLP.DLL, wich is found on all Win32 systems, except perhaps Win95 ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> I think you only need IMAGEHLP.DLL, wich is found on all Win32
> systems, except perhaps Win95 ?

Yep, according to http://tinyurl.com/2txv3 this DLL is present on Win 95
and upwards. (It doesn't list Win XP at that URL, but I'm assuming the
page is very old -- it certainly looks it). So there you go, Fangles! :)
Post Reply