PDA

View Full Version : Need help creating a file system


x213a
6th Mar 2010, 17:50
OS is XP pro.

How would I go about creating a file system of 2000 folders, each one named 0001-2000 respectivley?

The idea is to be able to scan paperwork into each folder and to be able to instantly access whichever folder by typing in 1234 for example.

Is there a way to create that many folders so named in a few clicks or would I have to manually create each one?

Thanks.

Saab Dastard
6th Mar 2010, 19:01
Create a batch (text) file in notepad called "create.bat" or something.

cd C:\ (or wherever you want to create them)
md 0001 0002... 1999 2000
exit

note - just separate the names with spaces.

Note 2 - probably not a good idea to put 2000 folders at the root of C!!

Run from a command prompt.

I would use Excel (or similar) to create the list, using dragging, then use Word to copy the table and convert to text, replace paragraph marks with spaces, then paste into the batch file. Takes about 2-3 minutes.

SD

ps - you could do clever things with a data file and create the batch file with a variable for foldername and pass the datafile to it, but if you are only doing this once and have to create the text for the datafile anyway, it's quicker to just "hardcode" it.

Gertrude the Wombat
6th Mar 2010, 20:23
I tried this with half a million once ... admittedly under NT, I don't know how much the file system has improved since then for this sort of nonsense.

I rapidly came to the conclusion that it was vastly better to put all the files into SQL Server and use indexes rather than try to use the filing system.

Cron
6th Mar 2010, 21:36
Classic database application.

You say scan paperwork which suggest no OCR and thus a need to store images of said documents.

Database would have 1 table (entity) with 2000 records, each record would have 2 fields (attributes). One field would hold the record identification (e.g. 1234 - BUT make sure you set the datatype as text NOT integer), the other field would hold the image.

MS Access can handle all this and has a fairly friendly GUI to assist in the setup.

Using a Database means you get all the tools built in for backup, repair, replication, sorting, searching (only on record identification field if the docs are images, suggest a third field which contains text key words relating to doc contents - this would be searchable).

Cron

PM if you need more help.

Mac the Knife
7th Mar 2010, 05:43
I loved DOS batch files!

Here is a crude way to do it (I'm sure there are better and neater batch constructs, but its too early on a Sunday morning for me...)

--------------------------------------------------

cls
@echo off

REM makedirs.bat
REM environmental variables used - intCounter

REM initialize test value to be "true"
SET intCounter=1

:while

REM test condition (set to 10 here)
IF %intCounter% GTR 10 (GOTO wend)

REM procedure where condition is "true"
md %intCounter%

REM set new test value
SET /a intCounter=intCounter+1

REM loop
GOTO while

:wend

PAUSE

-------------------------------------------------

:-)

Mac

Mac the Knife
7th Mar 2010, 06:03
Actually, thinking about it you could do it all in one command line (no need for environmental variables or batch files). 2000/XP only I'm afraid.

At the command line, in the directory where you want to create your folders, just type

FOR /L %A IN (1,1,10) DO md %A

This'll start the numbering at 1, increment by one each time and go on 'till 10

:-)

Mac

Bushfiva
7th Mar 2010, 07:10
But it doesn't do what he wants.

Mac the Knife
7th Mar 2010, 12:53
Oh alright then....its very clumsy but it works (tested up to 2000 directories - quite quick, a few seconds) - 2000/XP only I'm afraid.

Now I'll have to redo it in old DOS and solicit some initial user input and dress it up and make it pretty and make an executable and........

-------------------------------------------------------
cls

rem makedirs.bat

set /A counter=0
set filename=0
rem counter is numeric and filename is a string
:start
set /A counter=%counter%+1
if %counter% LEQ 9999 set filename=%counter%
if %counter% LEQ 999 set filename=0%counter%
if %counter% LEQ 99 set filename=00%counter%
if %counter% LEQ 9 set filename=000%counter%
md %filename%
rem Set your number of desired directories here (2000 in this case)
if %counter% EQU 2000 goto end
goto start
:end

-----------------------------------------------------------------------

......I'd forgotten what a PITA this stuff is.....

:-)

Mac

x213a
7th Mar 2010, 13:21
Thanks Mac, Could you please guide me on how to use that script? I've never tinkered with anything like that before. Cant test it at the moment as I'm at home and I'm not on XP. Something for the nightshift tonight.

Cheers.

Mac the Knife
7th Mar 2010, 14:17
Using Windows Explorer, navigate to My Documents or wherever you want the folders to be. Right-click and choose New - Folder and make a new folder - name it something suitable like Files or whatever. Go into the new folder and right-click again, but choose New - Text Document and make a new text document - by default it'll be called New Text Document.txt.

Double-click on this new document and it'll open for editing. Copy and paste everything between the purple dotted lines in my post, save the document (File - Save) and close/exit the editor.

Now you need to rename the New Text Document.txt - for simplicities sake call it makedirs.cmd - it MUST have either a .bat or a .cmd extension or it won't work -Windows may warn you about changing the extension but don't worry.

Once you have done that you can double-click on makedirs and it'll go off and make your 2000 directories (takes about 6 seconds on my machine) and off you go.

If this suits you then fine, but as others have pointed out this isn't the best way of handling a lot of data

Cheers

Mac

x213a
7th Mar 2010, 14:42
Thanks! Will give it a whirl tonight.:)

Mac the Knife
7th Mar 2010, 16:15
Here's a nicer version where you can choose how many directories to create
Note that I haven't implemented proper error trapping in the input yet

--------------------------------------------------
@echo off
cls
goto start

rem makedirs.cmd
rem Version 0.01.06
rem Creates multiple sequentially numbered subdirectories
rem Copyright ajbc - ajbc{#at#}iafrica.com
rem This utility starts from the directory that it finds itself in so
rem put it in the directory where you want to create the new subdirectories

:start
set /P numdirs=How many directories do you want to create?
rem get user input on number of directories to create
echo.
echo Please wait a moment while the directories are created
set /A counter=0
set filename=0
rem counter is numeric (forced by /A) and filename is a string (default)

:loop
set /A counter=%counter%+1
if %counter% LEQ 9999 set filename=%counter%
if %counter% LEQ 999 set filename=0%counter%
if %counter% LEQ 99 set filename=00%counter%
if %counter% LEQ 9 set filename=000%counter%
md %filename%
rem check if the counter has reached numdirs
if %counter% EQU %numdirs% goto end
rem exit when numdirs is reached
goto loop

:end
rem end batch and exit
-------------------------------------------------

Jeez I'm a sad bastard...............

Mac :-)

jimtherev
7th Mar 2010, 16:40
-------------------------------------------------

Jeez I'm a sad bastard...............

Mac :-)
Norrabitofit, Mac! Time was that's what we were all doing! Congrats for remembering way back when.
Jim

Feline
7th Mar 2010, 17:38
Respect!

I do like the sub-routine to add leading zeroes! Very elegant! Hear it was a trifle warm in your part of the world today - maybe the heat enhances the grey matter?

Mac the Knife
7th Mar 2010, 19:09
Well, here we are with error checking!

Why bother? Well, from my long ago days of DBase programming I'm still obsessive about sanitizing and checking input. Bad/unchecked input is how databases get corrupted or yield nonsensical answers, and its also how the bad guys are able to overflow buffers and inject code at runtime.

DOS/Windows environmental variables are untyped and string or arithmetical manipulations are limited, difficult and rather idiosyncratic but at last now the routine won't stall or go into an endless loop or produce unexpected output.

Rather appropriately I got my kitten to do fuzz testing by walking around on the keyboard and so far, so good - though I don't claim it is bulletproof.

-----------------------------------------------------------------------

@echo off
cls
goto start

rem makedirs.cmd
rem Version 0.01.10
rem Creates multiple sequentially numbered subdirectories
rem Copyright ajbc - ajbc{#at#}iafrica.com
rem This utility starts from the directory that it finds itself in so
rem put it in the directory where you want to create the new subdirectories

rem environmental variables used are numdir, counter and filename

:start
set /P numdirs=How many directories do you want to create?
rem get user input on number of directories to create

:chk_input
set /A number=%numdirs%
if %number% LEQ 0 goto error1
rem Catches most non-numeric input like "Fred" or "hotpants"
rem What is doesn't catch either causes an error2 or the batchfile simply exits
if %number% GTR 9999 goto error2
rem Catches numbers > 9999 and invalid input that error1 misses

:carry_on
echo.
echo Please wait a moment while the directories are created
set /A counter=0
set filename=0
rem counter is numeric (forced by /A) and filename is a string (default)

:loop
set /A counter=%counter%+1
if %counter% LEQ 9999 set filename=%counter%
if %counter% LEQ 999 set filename=0%counter%
if %counter% LEQ 99 set filename=00%counter%
if %counter% LEQ 9 set filename=000%counter%
md %filename%
rem check if the counter has reached numdirs
if %counter% EQU %numdirs% goto end
rem exit when numdirs is reached
goto loop

:error1
cls
echo Invalid input!
pause
goto start

:error2
cls
echo Invalid input or exceeds 9999 subdirectory limit!
pause
goto start

:end
rem tidy up (remove variables used from environment)
set numdirs=
set counter=
set filename=
rem end batch and exit

---------------------------------------------------------------------------

An old programmer's saying is that programs are never finished, merely abandoned!

Thank you x213a for taking my remaining little grey cells for a run (gasp! gasp!) and thank you Feline (yes, its bloody hot in Cape Town today!) and jimtherev for your kind words!

Mac

x213a
7th Mar 2010, 20:35
Thanks Mac:ok:

Works perfectly - just what I needed!

Now to start scanning...

:)