highend was gracious enough to author a script that would allow user to create multiple directories from text input:
viewtopic.php?p=199288#p199288
Would someone be able to modify this same concept to create sub-folders?
For example, there exists the following folders:
C:\Dir1
C:\Dir2
C:\Dir3
C:\Dir4
I'm looking for the ability to create an identical sub-folder in all the previously mentioned folders, e.g.:
C:\Dir1\Sub-FolderFromScript
C:\Dir2\Sub-FolderFromScript
C:\Dir3\Sub-FolderFromScript
C:\Dir4\Sub-FolderFromScript
The user should be able to specify the sub-folder name ideally, but having a hardcoded subfolder name that is applied to all parent folders would also be acceptable.
Thank you in advance.
Text 2 Sub-Folders
Re: Text 2 Sub-Folders
new(<curpath> . "\" . $folder, "dir");
new($folder, "dir");
?
One of my scripts helped you out? Please donate via Paypal
Re: Text 2 Sub-Folders
Thanks for the reply.
I tried replacing the line you mentioned and it seems to behave the same as the original script:
Code: Select all
/*
******************************************************************************
@Author : IT Services & Consulting Ulf Kohlmorgen
@Function: Create folders from .txt file or a manual list
@Tags : create, folder
@Version : v0.1
******************************************************************************
*/
$action = confirm("YES = Choose a .txt file<br>NO = Enter folder(s) manually<br>CANCEL = Exit", , 1, 3);
// 1 = Yes, 0 = No, 2 = Cancel
$folders = ""; $file = "";
switch ($action) {
case 2:
end true; break;
case 0:
$folders = input("Enter folder name(s)", "One name per line", "New Folder", "m", , 600, 400, , ":newfolder");
if ($folders) { CreateFolders($folders); }
break;
case 1:
$file = inputfile(, "txt", "Select the file...");
if ($file) { CreateFolders(readfile($file, , , 65001)); }
break;
}
function CreateFolders($input) {
$input = trim($input);
end ($input == ""), "No valid folder(s) given, aborted!";
foreach($folder, $input, <crlf>, "e") {
$folder = trim($folder);
if ($folder == "") { continue; }
new($folder, "dir");
}
}
C:\Test
C:\Test2
C:\Test3
C:\<Current_Script_Creates_Folder_Here>
Rather, I would like the script to create the new empty folders as sub-folders within existing directories:
C:\Test\<New_Script_Creates_Sub-Folder_Here>
C:\Test2\<New_Script_Creates_Sub-Folder_Here>
C:\Test3\<New_Script_Creates_Sub-Folder_Here>
Another illustration and use case:
C:\Movies\Shrek
C:\Movies\Shrek2
C:\Movies\Shrek3
C:\Movies\Shrek4
C:\Movies\Shrek5
C:\Movies\Shrek6
Function:
create an empty "Cover" folder within all existing directories from where the script is initiated, e.g. script launched from C:\Movies creates sub-folders within all Shrek directories.
Execution:
while sitting in C:\Movies path, script prompts for .txt or manual text input to create sub-folders within all existing directories (Shrek, Shrek2, etc.).
Assuming this is feasible, script would ideally be intelligent enough to automatically determine 7 instances of an empty "Cover" directory is required (due to only 7 folders existing in the path the script was launched from, C:\Movies), otherwise script should should allow batch sub-folder creation in all Shrek directories if user manually inputs "Cover" on 7 separate lines.
See attached image for further illustration:
- Attachments
-
- Script should create sub-folders within all parent folders of the path script is launched from
- XYplorer_NfTxdAIgqh.jpg (236.88 KiB) Viewed 725 times
Re: Text 2 Sub-Folders
There is no need to mention multiple folders with the same name. This function creates all entered (or read) folder names in all found subfolders (no recursion) inside the current dir.
So if you enter:
inside
it would create:
So if you enter:
Code: Select all
Cover 1
Cover 2
C:\Movies
it would create:
Code: Select all
C:\Movies\Shrek\Cover 1
C:\Movies\Shrek\Cover 2
C:\Movies\Shrek2\Cover 1
C:\Movies\Shrek2\Cover 2
C:\Movies\Shrek3\Cover 1
C:\Movies\Shrek3\Cover 2
C:\Movies\Shrek4\Cover 1
C:\Movies\Shrek4\Cover 2
C:\Movies\Shrek5\Cover 1
C:\Movies\Shrek5\Cover 2
C:\Movies\Shrek6\Cover 1
C:\Movies\Shrek6\Cover 2
Code: Select all
function CreateFolders($input) {
$input = trim($input);
end ($input == ""), "No valid folder(s) given, aborted!";
$subfolders = listfolder(, , 2, <crlf>);
end (!$subfolders), "No subfolder(s) found, aborted!";
foreach($subfolder, $subfolders, <crlf>, "e") {
foreach($folder, $input, <crlf>, "e") {
$folder = trim($folder);
if ($folder == "") { continue; }
new($subfolder . "\" . $folder, "dir");
}
}
}
One of my scripts helped you out? Please donate via Paypal
Re: Text 2 Sub-Folders
Perfect, this works great!
I really appreciate your help as always.
Here is the full "Text 2 Subfolders" script for those who are interested and posterity:
Code: Select all
/*
******************************************************************************
@Author : IT Services & Consulting Ulf Kohlmorgen
@Function: Create subfolders from .txt file or a manual list
@Tags : create, subfolder
@Version : v0.1
******************************************************************************
*/
$action = confirm("YES = Choose a .txt file<br>NO = Enter subfolder(s) manually<br>CANCEL = Exit", , 1, 3);
// 1 = Yes, 0 = No, 2 = Cancel
$folders = ""; $file = "";
switch ($action) {
case 2:
end true; break;
case 0:
$folders = input("Enter subfolder name(s)", "One name per line", "New Folder", "m", , 600, 400, , ":newfolder");
if ($folders) { CreateFolders($folders); }
break;
case 1:
$file = inputfile(, "txt", "Select the file...");
if ($file) { CreateFolders(readfile($file, , , 65001)); }
break;
}
function CreateFolders($input) {
$input = trim($input);
end ($input == ""), "No valid folder(s) given, aborted!";
$subfolders = listfolder(, , 2, <crlf>);
end (!$subfolders), "No subfolder(s) found, aborted!";
foreach($subfolder, $subfolders, <crlf>, "e") {
foreach($folder, $input, <crlf>, "e") {
$folder = trim($folder);
if ($folder == "") { continue; }
new($subfolder . "\" . $folder, "dir");
}
}
}
Re: Text 2 Sub-Folders
Just a quick reminder, if you need the same set of subfolders over and over in newly created folders, one can create this folder structure (even with more than one level and/or files in it) in the New Items folder of XY.
Once created one can then do a simple Edit/New Items/<name of folder structure> to instill the same set of folders and files into the current folder.
One highly underrated feature of XY that has been around for years.
Once created one can then do a simple Edit/New Items/<name of folder structure> to instill the same set of folders and files into the current folder.
One highly underrated feature of XY that has been around for years.
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
Re: Text 2 Sub-Folders
Thanks for your reply.
I've never utilize this feature before but I'm unsure it would help my specific use case.
I repeatedly need to create the previously mentioned "Cover" subfolders within ever changing parent folders, e.g. today I need these created:
C:\Movies\Movie1\Cover
C:\Movies\Movie2\Cover
C:\Movies\Movie3\Cover
Then tomorrow I may need these subfolders created:
C:\Music\Album999\Cover
C:\Music\Album2046\Cover
C:\Music\Album5842\Cover
Can the New Item feature accomplish this?
Otherwise, the script highend authored accomplishes this beautifully, although I'd be interested in an alternate or more efficient method.
Re: Text 2 Sub-Folders
Depends on what part of the structure is already there,
If all you need is the last .../Cover everywhere then yes it certainly will.
Read up on it in the help.
If all you need is the last .../Cover everywhere then yes it certainly will.
Read up on it in the help.
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)