Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Directory Create Utility
#1
Hi,

Instead of a directory delete utility like Silent,
why not build a directory create utility.

Attached is a directory create utility.

The difference between MKdir and MD is that
MD creates a directory and Makedir.bas makes an entire path..

For example, you could create \temp\newdir\nextdir\

Erik.


Attached Files
.zip   MAKEDIR.ZIP (Size: 1.81 KB / Downloads: 41)
Reply
#2
It threw me off when I was reading your code with all those dots in the variable names. I thought you left off some TYPE definition at first. Cool code.
Tread on those who tread on you

Reply
#3
I like using dots but mostly just when I use TYPEs, for the same reason.

So if I had

LINE INPUT "Make what Dir/Path: "

And input "myfolder\folder1\pete"

I would get a$ = "myfolder\folder1\pete"

Parse it out with INSTR()
myfolder
folder1
pete

Check for IF _DIREXISTS for each parsed dir name.

Make the directory if it does not exists.

Follow the parsing down the path to completion.

That's handy.

Does it also get into making multiple sub-directories like: myfolder/folder1, myfolder/folder2, etc.? I used to use a FOR/NEXT loop to assign sub-folders numbers with a MKDIR loop for that.

Pete
Reply
#4
And for me, unless I was needing to really create these directories all the time I'd just use PowerShell to do it once. You're probably not going to be making directories that often where the speed will be something critical. Usually, I make a program that checks for something existing and if it doesn't, it makes it. And if I was only needing it for that first launch, I'd just use PowerShell. Less code needed and you can still find out if it succeeded or not.
Tread on those who tread on you

Reply
#5
(09-16-2022, 03:18 PM)Pete Wrote: I like using dots but mostly just when I use TYPEs, for the same reason.

Does it also get into making multiple sub-directories like: myfolder/folder1, myfolder/folder2, etc.? I used to use  a FOR/NEXT loop to assign sub-folders numbers with a MKDIR loop for that.

Pete

@pete: Yes! I could easily add multiple paths on input. For example:

\temp1, \temp2, ...

and in quotes:

"\dir1\", "\dir2\", ...

in the attached file...

also adds GetLastError DisplayWinErrr.


Attached Files
.bas   MAKEDIR.BAS (Size: 4.74 KB / Downloads: 46)
Reply
#6
Nice!

Pete
Reply
#7
This is probably easier to do with VBScript (Windows Scripting Host).
The program example should show that you can also delete under Windows without asking. I have now changed it so that a folder is created via the query, which is then automatically after 5 seconds deleted again. That could certainly be easily converted to create any folder. In the end it's more of a gimmick. But one can learn from it.

In my example, the folder "Beispiel" is created in H:\Ablage\Beispiel. Adapt it to your own system when trying it out. Name: XYZ.vbs

Code: (Select All)
'Windows Scripting Host Beispiel, 15. April 2019/14. Sept. 2022
'Erstellt einen Ordner und löscht ihn nach 5 sek. ohne Abfrage

'Variablendeklaration erzwingen
Option Explicit

Dim Pfad, NeuerPfad, OrdnerAnzeigen
Dim fso, fo

NeuerPfad = Inputbox("Neuen Ordner mit Pfad angeben: ")
'Hier: H:\Ablage\Beispiel

Pfad = NeuerPfad

'FileSystemObject erzeugen fuer Zugriff
Set fso = WScript.CreateObject("Scripting.FileSystemObject")

'Pruefen ob Ordner schon existiert
If (Not fso.FolderExists(Pfad)) Then
'Ordner erstellen
Set fo = fso.CreateFolder(Pfad)
End If

'Neu erstellten Ordner anzeigen
OrdnerAnzeigen = fso.GetParentFolderName(Pfad)
Set fo = fso.GetFolder(OrdnerAnzeigen)

'5 Sekunden warten
WScript.Sleep 5000

'Ordner ohne Nachfrage loeschen
fso.DeleteFolder(Pfad)
WScript.Quit

'***Ende
Reply




Users browsing this thread: 2 Guest(s)