Reading from a File

T

Tom Sibley

I have the following script:

dir \\server\share\_* > Names.Txt
for /f "Skip=5 Tokens=4 Delims= " %%a in (Names.Txt) do md %%a
for /f "eol= Tokens=4,5 Delims=_,- " %%a in (Names.Txt) do (if exist
_%%a-%%b ren _%%a-%%b _%%a_%%b)

"Names.Txt"
01/08/2004 12:40p <DIR> _User-1
02/06/2004 12:42p <DIR> _User-2
0 File(s) 0 bytes
65 Dir(s) 51,539,935,232 bytes free


Line 01 Runs a directory of the server share and looks for folders with "_*"
and ports it to "Names.Txt"
Line 02 Reads the "Names.Txt" file and "md" makes a directory in the new
location
Line 03 Reads the "Names.Txt" to for variable fill in, then checks that the
folder exist and renames it from _User-1 to _User_1 etc.

Beacuse of the directory command "Bytes" is listed in Tokens=4 area and gets
created as a Folder

How do I end the read process before it gets to the "0 File(s) (0)bytes"
line?
 
M

Matthias Tacke

Tom Sibley said:
I have the following script:

dir \\server\share\_* > Names.Txt
for /f "Skip=5 Tokens=4 Delims= " %%a in (Names.Txt) do md %%a
for /f "eol= Tokens=4,5 Delims=_,- " %%a in (Names.Txt) do (if exist
_%%a-%%b ren _%%a-%%b _%%a_%%b)

"Names.Txt"
01/08/2004 12:40p <DIR> _User-1
02/06/2004 12:42p <DIR> _User-2
0 File(s) 0 bytes
65 Dir(s) 51,539,935,232 bytes free


Line 01 Runs a directory of the server share and looks for folders
with "_*" and ports it to "Names.Txt"
To really look for folders *only* I'd append /AD
Line 02 Reads the "Names.Txt" file and "md" makes a directory in the
new location
Which seems to be the current folder. (what about subfolders?)
Line 03 Reads the "Names.Txt" to for variable fill in, then checks
that the folder exist and renames it from _User-1 to _User_1 etc.
I suggest a different approach which doesn't create wrong names and
doesn't need the intermediate file.
Beacuse of the directory command "Bytes" is listed in Tokens=4 area
and gets created as a Folder
How do I end the read process before it gets to the "0 File(s)
(0)bytes" line?
Since you only want the folder name, why do you get a full dir and not a
basic /B one ?


@echo off
setlocal
for /f "delims=" %%A in ('dir \\server\share\_* /B /AD') do call :md "%%A"
goto :eof
:md
set Folder=%~1
set Folder=%Folder:-=_%
if Not exist "%Folder%" MD "%Folder%"

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top