#1 2012-09-11 09:38

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Creating a set of empty folders

Hi Denis,

I wanted to create 23 folders, each named after a design pattern name (GoF patterns).
The idea is to store the videos, sample code, cheat sheets, charts and tutorials in the respective folder.

I already have the 23 names. However, I do not have the contents (files) yet.

I came across such requirement in the past also, where I know the name of the topics in advance, and want to create a separate folder for each topic.

Is there a trick to create these (empty) folders in bulk?

-Narayan

Last edited by narayan (2012-09-11 09:38)

Offline

#2 2012-09-11 11:25

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Creating a set of empty folders

Best with an file manager.

Second best with an CMD / VBS / AHK script, asking for the names or reading an list.txt line-by-line

Then there are many already available tools for this issue (search: dummy file creator)


With ReNamer we can use UserInput, but then again we have to create the folder first too


This is an example to just create n files or folders:

CreateFiles.cmd

@ECHO OFF
set /p "amount=How many files do you want to create?"
for /l %%i in (1,1,%amount%) do (copy nul newxyz_%%i.txt >NUL)

CreateFolders.cmd

@ECHO OFF
set /p "amount=How many FOLDERs do you want to create?"
for /l %%i in (1,1,%amount%) do (MD newxyz_%%i >NUL)

Next use ReNamer UserInput to rename this dummy items with your list.


EDIT:
just had the wish to make that a lit bit more comfortable:

1.) ask what to create: FILEs or FOLDERs in one script
2.) ask how many to create
3.) ask for an optional prefix
4.) ask for an optional suffix (e.g. .txt for FILEs)

CreateFilesORFolders.cmd

@ECHO OFF
CLS
setLocal EnableDelayedExpansion
ECHO Dummy Files and Folder Creater & ECHO. & ECHO (Tip: enter X to exit)&ECHO.&ECHO.&ECHO.
set /p "item=What do you want to create? FILE or FOLDER? : "
if %item%==FILE GoTo _start
if %item%==FOLDER GoTo _start
if %item%==x GoTo EOF
if %item%==X GoTo EOF
ECHO.
ECHO Sorry, but  "%item%"  is not supported.  Please use upper case "FILE" or "FOLDER" here.
ECHO.
PAUSE
call %~0
GoTo EOF

:_start
set /p "amount=How many %item%s do you want to create? "
set /p "Prefix=Prefix the numbers by (optional, e.g. use Dummy_): "
set /p "Suffix=Suffix the numbers by (optional, e.g. use .txt): "
if %item%==FILE GoTo _FILE
:_FOLDER
for /l %%D in (1,1,%amount%) do (
    SET digit=0000%%D
      SET digit=!digit:~-4!
        MD %Prefix%!digit!%Suffix% )
GoTo _fin
:_FILE
for /l %%D in (1,1,%amount%) do (
    SET digit=0000%%D
      SET digit=!digit:~-4!
        COPY NUL %Prefix%!digit!%Suffix% )
GoTo _fin

:_fin
ECHO Finish.
PAUSE





And again,  create from an text list  _myLIST.txt

_myLIST.txt wrote:

Folder 1 ONE\sub Folder one
Folder 2 TWO
Folder 3 THREE\sub\Folder\three
Folder 4 FOUR\sub\Folder\4

CreateFilesORFoldersFromLIST.cmd

@ECHO OFF
SET myLIST=_myLIST.txt
CLS
setLocal EnableDelayedExpansion
ECHO Dummy Files and Folder Creater form %myLIST% & ECHO. & ECHO (Tip: enter X to exit)&ECHO.&ECHO.&ECHO.
set /p "item=What do you want to create from %myLIST%? FILE or FOLDER? : "
if %item%==FILE GoTo _start
if %item%==FOLDER GoTo _start
if %item%==x GoTo EOF
if %item%==X GoTo EOF
ECHO.
ECHO Sorry, but  "%item%"  is not supported.  Please use upper case "FILE" or "FOLDER" here.
ECHO.
PAUSE
call %~0
GoTo EOF

:_start
set /p "Prefix=Prefix the name from the list by (optional, e.g. use Dummy_): "
set /p "Suffix=Suffix the name from the list by (optional, e.g. use .txt): "
if %item%==FILE GoTo _FILE
:_FOLDER
for /F "delims=" %%F IN (%myLIST%) DO MD "%~dp0%Prefix%%%F%Suffix%"
GoTo _fin
:_FILE
for /F "delims=" %%F  IN (%myLIST%) DO COPY NUL "%~dp0%Prefix%%%F%Suffix%"
GoTo _fin

:_fin
ECHO Finish.
PAUSE

Last edited by Stefan (2012-09-11 12:42)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2012-09-11 12:29

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Creating a set of empty folders

Ah, but the best file manager (IMHO, xplorer2) cannot do that.

Is it possible to have a PascalScript for this? Then all I have to do is to save it and use it whenever I want!

Offline

#4 2012-09-11 13:59

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Creating a set of empty folders

narayan wrote:

Is it possible to have a PascalScript for this? Then all I have to do is to save it and use it whenever I want!

Theoretically it is possible, but it's somehow uncomfortable using it.

You need one file in the file list or at least something written in Analize Window (an then apply changes). If they are empty the script won't work.
Also another problem of this would be if the names are somewhat random, you might get more folders than you want if you apply the script unintentionally (because of how uncomfortable it is sometimes can go wrong).

Any way if you want to give it a try, this would be the basic mechanism.:

const
  // Here the path where the folders will be created
  BasePath = '';
  NumFolders = 23;

var
  FolderName: WideString;
  I: Integer;

begin
  if (BasePath = '') then Exit;

  for I:=1 to NumFolders do
  begin
    FolderName := '\Folder' + IntToStr(I);
    WideCreateDir(BasePath + FolderName);
  end;
end.

Sometime ago I tried to do it that way but never convinced me.

I usually create a bunch of copies of an empty folder, then rename them and delete the rest.

Last edited by SafetyCar (2012-09-11 14:06)


If this software has helped you, consider getting your pro version. :)

Offline

#5 2012-09-12 00:56

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Creating a set of empty folders

SafetyCar wrote:

I usually create a bunch of copies of an empty folder, then rename them and delete the rest.

This is what I do as well. I don't even bother with batch files unless I have have some really specific requirements. For generic bulk folder creation, when said folders will be renamed by a purpose-built tool such as ReNamer, simple copy-paste in Explorer suffices. I mean, create a folder, then Ctrl+C and keep Ctrl+V pressed to create a whole bunch of sequentially named folders - what can be simpler than that?

Last edited by Andrew (2012-09-12 00:57)

Offline

#6 2012-09-12 15:53

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Creating a set of empty folders

Using PascalScript is an good idea.

//// Create some dummy files or folders for testing purpose.
//// SafetyCar at http://www.den4b.com/forum/viewtopic.php?pid=6783#p6783

//// To actually create Files or Folders:
//// Add at least one file to the file list and press PREVIEW. Done!


const
  ////  = = =  User Settings = = =
  //// Here the path where the items will be created (must exist!) :
  //// Note:    '.\'  is relative to the ReNamer.exe,   and   'TEST\'  is my test folder there.
           WorkDir = '.\TEST\';
  //// How many new items (Folders or Files):
           Amount = 18;
  //// Base name for the new items:
           NewFolder = 'SubFolder_';
           NewFile   = 'DummyFile_';
  //// Which kind of item do you want to create today?
  ////    Use: =true or =false
           CreateFiles = true;
           CreateFolders = true;
  //// IF 'CreateFolders = true'; then create files inside too?
  ////    Use: =true or =false
           FolderWithFiles = true;


  //// = = =  The Code  = = =
var
  digit: WideString;
  I,file: Integer;

begin
  ////just to prohibit the hints
      FileName := FileName; FilePath := FilePath; 

  ////some checkings for the working dir
      if (WorkDir = '') then Exit;
      if (not WideDirectoryExists(WorkDir)) then
       begin ShowMessage('Working Dir ' + WorkDir 
                    + ' not found. Script quits.'); Exit; end;

    ////Show prompt at to many items, more then 0, 10, 100 or 1.000
     if (Amount > 0) then
         if (WideDialogYesNo('Do you REALLY want to'+#13#10
           +'create '+IntToStr(Amount)+' items into'  +#13#10
           + WorkDir + '?')=false) then Exit; 


  for I:=1 to Amount do
  begin
     //// Pad digit to length, here to {6}
     digit := '00000' + IntToStr(I);
     digit := ReplaceRegEx(digit,'.*(.{6})', '$1', false, true);
     ////----------------------------------------------------------    
     if (CreateFolders) then
     begin
       ////Create Folders:
       WideCreateDir(WorkDir + NewFolder + digit);
       if (FolderWithFiles) then
       begin
          ////Create Files insed each folder:
          for file:=1 to 10 do
              FileWriteContent(WorkDir + NewFolder + digit 
               + '\' + NewFile  + IntToStr(file) 
               + '.txt', 'ReNamer Dummy File');
          end;
       end;
       ////----------------------------------------------------------    
       if (CreateFiles) then
       begin
          ////Create Files:
         FileWriteContent(WorkDir + NewFile  
               + digit + '.txt', 'ReNamer Dummy File');
       end;
  end;
end.

.

Last edited by Stefan (2012-09-13 07:59)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#7 2012-09-12 16:19

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Creating a set of empty folders

Hi Stefan!

Thanks for this script.

BTW on compilation,  there are a couple of hints:

---------------------------
Information
---------------------------
Compiled successfully!

[Line 0] Hint: Variable 'FILEPATH' never used
[Line 0] Hint: Variable 'FILENAME' never used
---------------------------
OK   
---------------------------

Offline

#8 2012-09-12 16:38

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Creating a set of empty folders

I assume that this script needs one file from the target folder where the folders are to be added.

I wanted to create folders in my E:\Download\Design patterns\ path.

So I followed these steps:

1. saved the script with a name.
2. Added a file from my target folder to ReNamer.
3. Added the PascalScript rule. Selected the newly saved script.

Immediately I get this error:

---------------------------
Error
---------------------------
Preview process has been terminated due to a critical error:

Pascal Script Execute:
[Line 47] Exception: Cannot create file "E:\Download\Design patterns\TEST\SubFolder_000001\DummyFile_1.txt". The system cannot find the path specified.

---------------------------
OK   
---------------------------

What could be wrong?


[Edit] Just had a look at the script, and it seems to need relative path.
Instead, can we simply specify the absolute path of the folder where I want to add subfolders?

Last edited by narayan (2012-09-12 16:42)

Offline

#9 2012-09-12 16:47

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Creating a set of empty folders

Another thing is, I have a list of folders to start with. For example, in case oif GoF patterns, I would copy the names from Internet.

Another example: Suppose that a teacher wants to create x number of folders, each folder named after her students. Later she would add material related to each student in a dedicated folder. In this case too she would have a list of students (one per line).

To sum up, in both cases, we have a list on clipboard. ReNamer should create folders based on that.
Alternatively, we can paste the list in a text file and place it in the target folder. Then ReNamer can go ahead, and use the file as argument, ande create folders in that same folder.

Offline

#10 2012-09-12 17:50

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Creating a set of empty folders

>>[Line 0] Hint: Variable 'FILEPATH' never used

This is an HINT only for each declared variable which is not used in the script. That's normal.
Since the vars FILEPATH and FILENAME  are declared by default from ReName itself,
but they are not used in this script, you are informed. Make sense normally. It's funny in an case like that above.


>>Exception: Cannot create file
The working dir mentioned in the script must be existent!
It can be relative or absolute.
'.\' revers here to the folder where the ReNamer.exe is started from.
'.\TEST\' revers to an folder named TEST in my ReNamer folder.
You can also us an absolute path as "E:\Download\Design patterns\"
(but then i think i have not tested with spaces in path...)


>>I assume that this script needs one file from the target folder
No.
Any file from anywhere, or even an 'X' in the analyzer window will do.
It's just that ReNamer do the action.



>>I have a list of folders to start with.

Could all be done, maybe.
But this is an issue for an separate tool like an file manager.

The above script is meant to create just a few files or folders
to rename after that with UserInput to create some test files.
OTHO, this is not really needed for ReNamer since it has that Analyzer tool (Shift+A)
But it was just for the fun and get familiar with PascalScript.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB