Multiple folders creation "MD" command.

English support forum

Moderators: Stefan2, white, sheep, Hacker

User avatar
ts4242
Power Member
Power Member
Posts: 2054
Joined: 2004-02-02, 20:08 UTC
Contact:

Re: Multiple folders creation "MD" command.

Post by *ts4242 » 2019-05-19, 19:59 UTC

Usher wrote:
2019-05-19, 12:14 UTC
2ts4242
Don't you think that the supposed command is too long to fit in a single line?
How do you want to split the content to many lines in Notepad?
Who said we need to split names to many lines, the file doesn't contain any command, so it is depend on the used script how it is parse the content.

User avatar
tridy
Junior Member
Junior Member
Posts: 86
Joined: 2003-11-27, 07:51 UTC
Location: Stockholm, Sweden

Re: Multiple folders creation "MD" command.

Post by *tridy » 2019-05-22, 06:08 UTC

depending on what you are using as a source for your list of folders, the challenge could be to actually handle such a long list and not the creating of the folders. I would put every folder name on a separate line and sort them alphabetically so I could add or remove folders easily, then use some tool to read line by line and create the folders. If you have not found the solution yet, it can be done in powershell or even withing excel with vba. Have you already found the solution, or do you want the powershell script?
[tridy]
License #: 79539

User avatar
Usher
Senior Member
Senior Member
Posts: 383
Joined: 2011-03-11, 10:11 UTC

Re: Multiple folders creation "MD" command.

Post by *Usher » 2019-05-22, 22:03 UTC

clifford_cooley wrote:
2019-05-19, 13:32 UTC
Are we arguing about how to create an invalid syntax for a command-line command? If it is not invalid, please explain. Nothing I have ever read suggest more than one folder can be created from the same script line.
What script do you mean - cmd? The picture shows Notepad with a very long single line containing a command md and a list of folders. This line is definitely too long for cmd commands.
clifford_cooley wrote:
2019-05-19, 13:32 UTC
From MD help text, each nested folder* needs its own MD command line.
1. The list does NOT contain nested folders.
2. You can create nested folders using one command, f.e.

Code: Select all

md a1\a2\a3\a4\a5
…if you enable cmd command extensions:
https://www.itprotoday.com/windows-78/how-do-i-enabledisable-command-extensions
clifford_cooley wrote:
2019-05-19, 14:03 UTC
MD "Folder One" "Folder Two"
But then there is a max character limit of 8191 (pre-XP: 2047) for each command line.
Oh, I see you already know what I mean. That's it. It works the same way in Windows XP. But inserting new lines is a job for regular expressions and in Windows XP you can't use Notepad even for "Replace all" (it takes long minutes…).
Regards from Poland
Andrzej P. Wozniak

User avatar
Usher
Senior Member
Senior Member
Posts: 383
Joined: 2011-03-11, 10:11 UTC

Re: Multiple folders creation "MD" command.

Post by *Usher » 2019-05-23, 00:24 UTC

ts4242 wrote:
2019-05-19, 19:59 UTC
Usher wrote:
2019-05-19, 12:14 UTC
2ts4242
Don't you think that the supposed command is too long to fit in a single line?
How do you want to split the content to many lines in Notepad?
Who said we need to split names to many lines, the file doesn't contain any command, so it is depend on the used script how it is parse the content.
What scripting, what parsing? Why are you trying to reinvent wheel?
The simplest answer to the SUBJECT is to create batch file (a.k.a. cmd script) and it's enough to use good text editor to do it. It's just one or two "replace all" using regular expressions.
Regards from Poland
Andrzej P. Wozniak

User avatar
tridy
Junior Member
Junior Member
Posts: 86
Joined: 2003-11-27, 07:51 UTC
Location: Stockholm, Sweden

Re: Multiple folders creation "MD" command.

Post by *tridy » 2019-05-24, 13:08 UTC

in case powershell is an option, and
if you have a names.txt file with the names of the folders each on a separate line, like this:

Code: Select all

MD Conscientia libera (CL)
Conscientia transmigrans
Consciex anticonflictiva
Consciex libera (CL)
Consciex Livre (CL)
Homo alienatus
Homo animalis
Homo autotortor
Homo bellicosus regressivus
Homo bellicosus transmigrabilis
...
here is a powershell script (save it as .ps1 file, and run in the same folder as names.txt file) that creates the folders:

Code: Select all

$dirs = Get-Content -Path "names.txt"
ForEach ($dir in $dirs)
{
    New-Item -Path $dir -Type Directory
}
[tridy]
License #: 79539

User avatar
Stefan2
Power Member
Power Member
Posts: 2487
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Multiple folders creation "MD" command.

Post by *Stefan2 » 2019-05-24, 13:30 UTC

tridy wrote:
2019-05-24, 13:08 UTC
...

Good work, tridy.


You can take this even shorter:
Get-Content .\List.txt | ForEach{ New-Item -Path $_ -ItemType Directory }

or even shorter
gc .\List.txt|%{New-Item $_ -i dir}


or as TC button:
Command: PowerShell -NoExit
Parameters: gc '%P%N'|%%{New-Item $_ -i dir}
Icon: powershell
Tooltip: create folders from selected list file



- - -

or for Pakylibin original comma separated list:

(Get-Content ".\List - comma separated.txt")-split',' |ForEach{New-Item -Path $_.trim() -ItemType directory}





 

Post Reply