Creating multiple folders from a list
Moderators: fgagnon, nikos, Site Mods
Creating multiple folders from a list
I don't know if we have discussed this before, but it seems so basic that I am surprised that I couldn't find it in a search.
The application is this: I start with a list of names (each name in a new line).
I want to create new folders with those names.
A typical example: I have 23 names of design patterns. Now I want to create 23 empty folders having those names. Later on I will populate them with useful articles, videos etc on each pattern.
Another example: I have a list of 50 persons. I want to create 50 empty folders with their names. Later on I will populate them with items received from these people.
And so on...
The application is this: I start with a list of names (each name in a new line).
I want to create new folders with those names.
A typical example: I have 23 names of design patterns. Now I want to create 23 empty folders having those names. Later on I will populate them with useful articles, videos etc on each pattern.
Another example: I have a list of 50 persons. I want to create 50 empty folders with their names. Later on I will populate them with items received from these people.
And so on...
This is a simple enough scripting task. You can't write it yourself? Unfortunately, that crack about:
...naturally prevents me from catering to your every whim. No one, and I mean no one, can fully appreciate how much work it is maintaining a suitably pretentious mien in these days of woe.narayan wrote:The problem is his garbage collector does not work
Ok, fine - I wrote it for you - the better part of valour is boredom, apparently.
Download it here: Folderer
A simple command-line utility which wants two parameters:
Folderer.EXE <FolderList> <ParentFolder>
<FolderList> is a file containing as many names of folders as you want created, 1 per line. If no file extension is given, ".TXT" is assumed. If no path is given, it is assumed to be in the same folder as the executable.
<ParentFolder> is optional - if it is provided then the folders will be created within it. If it is not provided then the folders will be created in the same folder as <FolderList> is located.
If a name in the <FolderList> file contains a full path then <ParentFolder> will be ignored for that item. If no path is given, then the folder will be created in <ParentFolder>. If a relative folder-path is used, it will be created relative to <ParentFolder>. Blank lines within <FolderList> will be ignored.
If a folder of the same name path already exists, it (and its contents) will be left alone.
If, for whatever reason, the creation of the new folder fails, you're given the option to Abort, Try Again, or Ignore that particular item.
Download it here: Folderer
A simple command-line utility which wants two parameters:
Folderer.EXE <FolderList> <ParentFolder>
<FolderList> is a file containing as many names of folders as you want created, 1 per line. If no file extension is given, ".TXT" is assumed. If no path is given, it is assumed to be in the same folder as the executable.
<ParentFolder> is optional - if it is provided then the folders will be created within it. If it is not provided then the folders will be created in the same folder as <FolderList> is located.
If a name in the <FolderList> file contains a full path then <ParentFolder> will be ignored for that item. If no path is given, then the folder will be created in <ParentFolder>. If a relative folder-path is used, it will be created relative to <ParentFolder>. Blank lines within <FolderList> will be ignored.
If a folder of the same name path already exists, it (and its contents) will be left alone.
If, for whatever reason, the creation of the new folder fails, you're given the option to Abort, Try Again, or Ignore that particular item.
Code: Select all
#include <File.au3>
#include <Misc.au3>
If $CmdLine[0] > 0 Then
Global $List, $i, $Parent, $Source, $Count = 0
If $CmdLine[0] = 1 Then
$Parent = StringMid($CmdLine[1], 1, StringInStr($CmdLine[1], "\", 0, -1))
Else
$Parent = $CmdLine[2]
EndIf
$Source = _Iif(StringInStr($CmdLine[1], "."), $CmdLine[1], $CmdLine[1] & ".txt")
If StringRight($Parent, 1) <> "\" Then $Parent &= "\"
If Not StringInStr($Source, "\") Then
$Source = @ScriptDir & "\" & $Source
If $CmdLine[0] = 1 Then $Parent = @ScriptDir & "\"
EndIf
If _FileReadToArray($Source, $List) = 0 Then
MsgBox(16, "Folderer", "Unable to Open ListFile" & @CRLF & @CRLF & $Source)
Exit
EndIf
For $i = 1 To $List[0]
If $List[$i] = "" Then ContinueLoop
If Not StringInStr($List[$i], ":") Then $List[$i] = $Parent & $List[$i]
If FileExists($List[$i]) Then ContinueLoop
If DirCreate($List[$i]) = 0 Then
Switch MsgBox(18, "Folderer", "Unable to Create New Folder:" & @CRLF & @CRLF & $List[$i])
Case 3 ; Abort
ExitLoop
Case 4 ; Try Again
$i -= 1
ContinueLoop
Case 5 ; Ignore
ContinueLoop
EndSwitch
EndIf
$Count += 1
Next
MsgBox(0, "Folderer", "Folders Created: " & $Count & _Iif($Count = $List[0], "", " Failed: " & $List[0] - $Count))
Else
MsgBox(16, "Folderer", "Expected Syntax: " & @CRLF & @CRLF & "FOLDERER.EXE <ListFile> <Parent Location>")
EndIf
So how about fitting this in the greatest dual-pane explorer on Earth?
Here's the imagined scenario:
1. When I press F8, x2 opens a multi-line text box.
2. If I enter a single name, x2 creates a single folder.
x2 allows me to create a multiline list by-
(a) entering name followed by <Enter>, or-
(b) pasting a multiline list in the box.
When I finally press OK, x2 creates those multiple folders.
Here, the penalty is that for a single folder, you cannot complete the command by pressing <Enter>. You have to click on the OK button.
Alternatively, let SHFT+F8 pop up a multi-line box.
In that case, the F8 shortcut can work as before.
Here's the imagined scenario:
1. When I press F8, x2 opens a multi-line text box.
2. If I enter a single name, x2 creates a single folder.
x2 allows me to create a multiline list by-
(a) entering name followed by <Enter>, or-
(b) pasting a multiline list in the box.
When I finally press OK, x2 creates those multiple folders.
Here, the penalty is that for a single folder, you cannot complete the command by pressing <Enter>. You have to click on the OK button.
Alternatively, let SHFT+F8 pop up a multi-line box.
In that case, the F8 shortcut can work as before.
Probably because you said it yourself: "I am surprised that I couldn't find it in a search."narayan wrote:So how about fitting this in the greatest dual-pane explorer on Earth?
A good idea is not born of the esoteric wishes of a single user - a good idea is born when it's actually more useful in application than substantive in the imagination.
Besides, the above script can easily be rewritten to include a GUI which would behave as you imagine, including all the possible error trapping which could occur (what if the user types an illegal character, does it fail in creation or are they all pre-checked?) And then no doubt you'll wonder why this can't be applied to <F7> as well... and while we're at it, let's add multiple common extensions for <F7>. And so on.
This is, after all, why scripting exists - so we can do the little stuff ourselves.
A more intuitive implementation occurred to me:
Here's the revised imagined scenario:
1. When I press F8, x2 opens a NORMAL text box.
If I enter a single name, and then press OK or press ENTER, x2 creates a single folder.
This is exactly as before (no change). But-
2. x2 allows me to create a multiline list by-
(a) entering name followed by a line-break with CTRL+Enter, or-
(b) pasting a multiline list in the box.
When I finally press OK or press ENTER, x2 creates those multiple folders.
Here's the revised imagined scenario:
1. When I press F8, x2 opens a NORMAL text box.
If I enter a single name, and then press OK or press ENTER, x2 creates a single folder.
This is exactly as before (no change). But-
2. x2 allows me to create a multiline list by-
(a) entering name followed by a line-break with CTRL+Enter, or-
(b) pasting a multiline list in the box.
When I finally press OK or press ENTER, x2 creates those multiple folders.
The idea of using a script with x2 is just like having an outhouse at the back of Buckingham Palace. Of course we are not amused!
And here is a funny story: I posed the same problem at ReNamer, and they also came up with two OTHER scripts, and finally the suggestion to copy an empty folder multiple times, and then rename them all using a UserInput rule (in which I can paste my list of names).
That proves this adage: "If all you have is a hammer, everything will look like a nail to you."
****
BTW the regular users of F8 won't even know that the GUI has an overloaded function. They will simply enter a name and press ENTER.
Power users will either paste a list in the box, or insert line-breaks by pressing CTRL+ENTER. (Let the window auto-size when more content is added.)
Note that this shortcut is fairly standard: You even do it in chat clients to insert a line-break, and also in MS Excel and OpenOffice Calc.
So there is no question of confusing the regular OR power users.
PLEASE let us have this feature!
And here is a funny story: I posed the same problem at ReNamer, and they also came up with two OTHER scripts, and finally the suggestion to copy an empty folder multiple times, and then rename them all using a UserInput rule (in which I can paste my list of names).
That proves this adage: "If all you have is a hammer, everything will look like a nail to you."
****
BTW the regular users of F8 won't even know that the GUI has an overloaded function. They will simply enter a name and press ENTER.
Power users will either paste a list in the box, or insert line-breaks by pressing CTRL+ENTER. (Let the window auto-size when more content is added.)
Note that this shortcut is fairly standard: You even do it in chat clients to insert a line-break, and also in MS Excel and OpenOffice Calc.
So there is no question of confusing the regular OR power users.
PLEASE let us have this feature!
So, not only was Nikos your second choice for this, but you've already rejected three scripts just because you live in a minority world of iPhones and Chat Client GUI's? And you don't see anything odd/spoilt about this being a self-described power-user? Are you sure your account hasn't been hacked? You're normally a bit more copped-on about things.
Besides, looking at it logically, if you commonly work within this paradigm (and you would appear to be the only one) - actually populating these folders with information would not itself be handled manually, it would be more DB oriented - which begs the question why the DB programme can't automatically create the folders as it goes? And if, indeed, you do all the work manually - why is using a script (I even offered a GUI version, you'll note) so arduous?
Besides, looking at it logically, if you commonly work within this paradigm (and you would appear to be the only one) - actually populating these folders with information would not itself be handled manually, it would be more DB oriented - which begs the question why the DB programme can't automatically create the folders as it goes? And if, indeed, you do all the work manually - why is using a script (I even offered a GUI version, you'll note) so arduous?
- FrizzleFry
- Platinum Member
- Posts: 1241
- Joined: 2005 Oct 16, 19:09
For me the fact that x2 easily interacts with scripts and external programs is what makes it so useful... I don't see why you're reluctant to use scripts...narayan wrote:The idea of using a script with x2 is just like having an outhouse at the back of Buckingham Palace. Of course we are not amused!
Here is a fast and dirty one:
for /F %%f in (list.txt) do md "%%f"
btw, what is generating your list of folder names?
Ah if the option is between sitting in grass and outhouse, then my choice would be the outhouse.
But I'd prefer an indoor facility right inside the Palace (with a bidet spouting rosewater).
You mean your half line will achieve whatever ~K's reams of script will do?
@Source of list of folder names:
Copy+paste from Internet, what else?
But I'd prefer an indoor facility right inside the Palace (with a bidet spouting rosewater).
You mean your half line will achieve whatever ~K's reams of script will do?
@Source of list of folder names:
Copy+paste from Internet, what else?
My "reams" are just the standard error checking with visual feedback if something goes wrong, path assumption/replacement options, etc. But, effectively, yeah, the short and dirty method works too.narayan wrote:You mean your half line will achieve whatever ~K's reams of script will do?
So now we're up to four scripts your rejecting? And... neglecting to thank the authors for their efforts in building your doomed Taj Mahal... Or were the poor workers then put to death afterwards to preserve the secrets, as so often happens in my dreams of the pyramids, and there was no need of a tradition for thanking us undesirable classes and our useless toils?
Disclaimer: Yes, I am aware historically that the pyramids were not actually built by slaves, etc, but that doesn't make for a very interesting story, so I'll stick with the mythical revisionism which suits my image of the world (from the point of view of a lowly garbage collector).
Of course thanks go to all the outhouse builders, but what I want is a nice airconditioned WC with modern plumbing.
The Rolls Royce owners are used to certain level of finesse, you see.
I'd want an umbrella concealed in the door.
http://www.rolls-roycemotorcars.com/med ... 7448794715
The Rolls Royce owners are used to certain level of finesse, you see.
I'd want an umbrella concealed in the door.
http://www.rolls-roycemotorcars.com/med ... 7448794715