Page 1 of 1
Creating folders provided by text file
Posted: 03 Mar 2009 04:04
by psyghotic
Hi,
I created a batchfile that creates a folder and copies a file in it.
I have to run it like this : makenotes jdoe
Then it creates a folder on server called jdoe and copies a file in it.
if I have 10 users i have to perform this action 10 times.
the code is :
Code: Select all
if not exist \\server\Home\%1 goto :noads
if exist \\server\Notesprofiles\%1 goto :exist
goto proceed
:exist
echo.
echo Notes Profile Folder already exists!
echo.
goto end
:noads
echo.
echo No ADS-Homefolder found!
echo.
goto :end
:proceed
echo.
echo Creating Notesprofile Directory...
md \\server\Notesprofiles\%1
echo Copying Notes INI-File...
copy \\server\Notesprofiles\000_sample_notes_data_folder\Lotus_Notes_80x_on_English_OS\notes.ini \\Maa-fs-01\server\%1
echo Adjusting permissions of the Notesprofile Directory...
cacls \\server\%1 /e /t /g %1:c
cacls \\server\%1 /e /t /g %1:r
cacls \\server\%1 /e /t /g %1:w
echo Done.
echo.
:end
I want to have a situation that :
If I create a textfile where I place all usernames.
My batchfiles reads this textfile and does the same as the above script.
so textfile is :
I can get these usernames in the textfile from an excel sheet, so just copy paste.
jdoe
jan
bla
and my batchfile reads this textfile and does what the above batch does.
I can get these usernames in the textfile from an excel sheet, so just copy paste.
Posted: 03 Mar 2009 05:12
by psyghotic
Hi,
I got it so far that it reads the first line of the textfile and performs all commands.
But I can't get it to loop trough all names in the textfile.
code :
Code: Select all
@echo off
for /f "tokens=*" %%A in (adsusers.txt) do ECHO
set /p arg=<"adsusers.txt"
if not exist c:\test\Home\%arg% goto :noads
if exist c:\test\Notesprofiles\%arg% goto :exist
goto proceed
:exist
echo.
echo Notes Profile Folder already exists for %arg%!
echo.
goto end
:noads
echo.
echo No ADS-Homefolder found for %arg%!
echo.
goto :end
:proceed
echo.
echo Creating Notesprofile Directory...
md c:\test\Notesprofiles\%arg%
echo Copying Notes INI-File...
copy \\server\Notesprofiles\000_sample_notes_data_folder\Lotus_Notes_80x_on_English_OS\notes.ini c:\test\Notesprofiles\%arg%
echo Adjusting permissions of the Notesprofile Directory...
cacls c:\test\Notesprofiles\%arg% /e /t /g %1:c
cacls c:\test\Notesprofiles\%arg% /e /t /g %1:r
cacls c:\test\Notesprofiles\%arg% /e /t /g %1:w
echo Done.
echo.
:end
pause
So what it does now.
The textfile contains :
jdoe
jane
test
My batchfile only reads jdoe from the textfile and doesn't read the next lines.
if I get this working that it reads multiple lines one after the other, i got my desired batchfile.
Posted: 03 Mar 2009 08:03
by RElliott63
Code: Select all
@echo off
if not exist c:\test\Home\adsusers.txt goto noads
for /f "tokens=*" %%A in (adsusers.txt) do (
if NOT exist c:\test\Notesprofiles\%%A (
echo.
echo Creating Notesprofile Directory %%A...
md c:\test\Notesprofiles\%%A
echo Copying Notes INI-File...
copy \\server\Notesprofiles\000_sample_notes_data_folder\Lotus_Notes_80x_on_English_OS\notes.ini c:\test\Notesprofiles\%%A
echo Adjusting permissions of the Notesprofile Directory...
cacls c:\test\Notesprofiles\%%A /e /t /g %1:c
cacls c:\test\Notesprofiles\%%A /e /t /g %1:r
cacls c:\test\Notesprofiles\%%A /e /t /g %1:w
) Else (
echo.
echo Notes Profile Folder already exists for %%A!
echo.
)
)
Goto End
:noads
echo.
echo No ADS-Homefolder found for Adsusers.txt
echo.
:End
echo Done.
echo.
pause
Posted: 03 Mar 2009 11:50
by psyghotic
This did the trick.
so thanks for all the advice
Code: Select all
@echo off
for /f "tokens=*" %%A in (adsusers.txt) do (
if not exist c:\test\Home\%%A (
echo %date%,%time% : No ADS-Homefolder found for %%A >> log.txt
) else if NOT exist c:\test\Notesprofiles\%%A (
echo.
echo Creating Notesprofile Directory %%A...
md c:\test\Notesprofiles\%%A
echo Copying Notes INI-File...
copy \\server\Notesprofiles\000_sample_notes_data_folder\Lotus_Notes_80x_on_English_OS\notes.ini c:\test\Notesprofiles\%%A
echo Adjusting permissions of the Notesprofile Directory...
cacls c:\test\Notesprofiles\%%A /e /t /g %1:c
cacls c:\test\Notesprofiles\%%A /e /t /g %1:r
cacls c:\test\Notesprofiles\%%A /e /t /g %1:w
) Else (
echo.
echo %date%,%time% : Notes profile folder already exists for %%A >> log.txt
echo.
)
)
Goto End
:End
echo Done.
echo.
pause
Posted: 19 Mar 2009 10:34
by avery_larry
Could also do this:
Code: Select all
for /f "delims=" %%a in (adsusers.txt) do call :process "%%~a"
goto :eof
:process
if not exist \\server\Home\%1 goto :noads
if exist \\server\Notesprofiles\%1 goto :exist
goto proceed
:exist
echo.
echo Notes Profile Folder already exists!
echo.
goto end
:noads
echo.
echo No ADS-Homefolder found!
echo.
goto :end
:proceed
echo.
echo Creating Notesprofile Directory...
md \\server\Notesprofiles\%1
echo Copying Notes INI-File...
copy \\server\Notesprofiles\000_sample_notes_data_folder\Lotus_Notes_80x_on_English_OS\notes.ini \\Maa-fs-01\server\%1
echo Adjusting permissions of the Notesprofile Directory...
cacls \\server\%1 /e /t /g %1:c
cacls \\server\%1 /e /t /g %1:r
cacls \\server\%1 /e /t /g %1:w
echo Done.
echo.
:end
Basically you just add these 3 lines at the beginning:
Code: Select all
for /f "delims=" %%a in (adsusers.txt) do call :process "%%~a"
goto :eof
:process
and the rest can then be unchanged.
AVERY
Posted: 19 Mar 2009 15:35
by *SCRIPTER*
Hey AVERY do you write any of your own code or do you just go
around mocking other peoples code, because from all your post I've found
between here and ss64 seems you just like to think you are god
To bad there is no god and you def are not her.