Computer Hope

Microsoft => Microsoft DOS => Topic started by: dakota on June 26, 2006, 10:33:57 AM

Title: multipule lines as a var
Post by: dakota on June 26, 2006, 10:33:57 AM
when i do this line and i echo the %%a it show all of the itomes but when it is set to a var it only does the first line

this is the line
Code: [Select]
for /f "tokens=1 delims= " %%a in ('dir /AD ^| findstr /R /V "\.\>" ^| find /c "<DIR>"') do set dirs=%%a
echo %dirs%
pause
for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a

echo %list%
Title: Re: multipule lines as a var
Post by: dakota on June 26, 2006, 01:21:17 PM
any help :-? :-? :-? :-?
Title: Re: multipule lines as a var
Post by: dakota on June 26, 2006, 09:30:19 PM
please help
Title: Re: multipule lines as a var
Post by: ghostdog74 on June 26, 2006, 10:56:11 PM
when you do the set var = %%a , you should do something with it.
Title: Re: multipule lines as a var
Post by: dakota on June 26, 2006, 11:45:13 PM
what do you mean i  set the list to a var and when i echo it it only gets the first line so my line looks like this

for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a & set list=%%a
Title: Re: multipule lines as a var
Post by: dakota on June 26, 2006, 11:46:21 PM
and i use the list var latter
Title: Re: multipule lines as a var
Post by: uli_glueck on June 27, 2006, 12:08:06 AM

You have to use a sub - procedure.

for /f "skip=%dirs%" %%a in ('dir /b /o:g') do call :sub %%a

set dirs=
goto :eof
:sub %%a

set  dirs=%1
pause
for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a

echo %list%

hope it helps
uli
Title: Re: multipule lines as a var
Post by: dakota on June 27, 2006, 09:36:38 AM
ok think you but i still cant get it to work here is all of my code:
Code: [Select]
@echo off
:start
::================================================
set fup=fup
set pur=purge
set alt=altpr
set sec=secure
set cod=,code 100
set ccc=,"cccc"
set Infile=temp.dak
set Outfile=purge.jim
::================================================
for /f "tokens=1 delims= " %%a in ('dir /AD ^| findstr /R /V "\.\>" ^| find /c "<DIR>"') do set dirs=%%a
echo %dirs%
pause
::for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %fup% %pur% %%a >testttt.txt& set list=%%a

for /f "skip=%dirs%" %%a in ('dir /b /o:g') do call :sub %%a
set dirs=
goto :eof
:sub %%a
set  dirs=%1
for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a  
echo %list%

pause
::for /f "delims=" %%a in ("%list%") do echo %fup% %pur% %%a>>%Outfile%
::echo.>>%Outfile%
::for /f "delims=" %%a in ("%list%") do echo %fup% %alt% %%a %cod%>>%Outfile%
::echo.>>%Outfile%
::for /f "delims=" %%a in ("%list%") do echo %fup% %sec% %%a %ccc%>>%Outfile%
::echo.>>%Outfile%
::pause
Title: Re: multipule lines as a var
Post by: dakota on June 27, 2006, 08:56:49 PM
anyone
Title: Re: multipule lines as a var
Post by: GuruGary on June 27, 2006, 10:03:19 PM
What are you trying to accomplish?  Let me know and I will be glad to help.
Title: Re: multipule lines as a var
Post by: dakota on June 27, 2006, 11:53:19 PM
I am trying to get a list of all the files in a directory and output them to a file but I want this list to be in the bare formate and have no folders included in it just the files. :P ::) ;D ;D Think you
Title: Re: multipule lines as a var
Post by: ghostdog74 on June 28, 2006, 02:46:36 AM
@echo off

for /F %%i in ('dir /A-D /S /B') do (
      echo %%~ni >> output.txt
)
Title: Re: multipule lines as a var
Post by: uli_glueck on June 28, 2006, 02:57:35 AM
So you don`t need to set it in a variable.
Ghostdogs solution seems perfect. :-)
Title: Re: multipule lines as a var
Post by: dakota on June 28, 2006, 10:08:22 AM
nope that dose not work i need it not to display directorys but all of the files and i would like to have it in a var because i will use the var later when i am adding things to it the it will go to the output file.
Title: Re: multipule lines as a var
Post by: Sidewinder on June 28, 2006, 01:24:33 PM
After reading this post, I'm guessing you want one variable to hold all the file names as if it were a collection. You can accomplish this by concatenating the files/dir names out of the FOR:

call set list=%list%%%a

Unfortunately, the result will be one long string. Unless you're running MS-DOS as your operating system and have access to the ANSI.SYS driver, there is no way to insert CRLF (carriage return/linefeed) characters between the file names in batch language.

Try using one of the Windows scripting languages where you have access to functions to represent the CRLF characters.

 8-)
Title: Re: multipule lines as a var
Post by: dakota on June 28, 2006, 02:49:42 PM
i could have it go only to a file and have my batch file use that file and then out put to a new file and delete the temp file with the file list in it.
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 09:35:31 PM
any help because when i have it go out to a file it goes out as only the first line.
Title: Re: multipule lines as a var
Post by: GuruGary on June 29, 2006, 10:18:43 PM
Post your code so we can help you troubleshoot the problem.
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 10:32:09 PM
@echo off
:start
::================================================
set fup=fup
set pur=purge
set alt=altpr
set sec=secure
set cod=,code 100
set ccc=,"cccc"
set Infile=temp.dak
set Outfile=purge.jim
::================================================
for /f "tokens=1 delims= " %%a in ('dir /AD ^| findstr /R /V "\.\>" ^| find /c "<DIR>"') do set dirs=%%a
echo %dirs%
pause
::for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %fup% %pur% %%a >testttt.txt& set list=%%a

for /f "skip=%dirs%" %%a in ('dir /b /o:g') do call :sub %%a
set dirs=
goto :eof
:sub %%a
set  dirs=%1
for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a  
echo %list%

pause
::for /f "delims=" %%a in ("%list%") do echo %fup% %pur% %%a>>%Outfile%
::echo.>>%Outfile%
::for /f "delims=" %%a in ("%list%") do echo %fup% %alt% %%a %cod%>>%Outfile%
::echo.>>%Outfile%
::for /f "delims=" %%a in ("%list%") do echo %fup% %sec% %%a %ccc%>>%Outfile%
::echo.>>%Outfile%
::pause
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 10:34:03 PM
the part at the bottom with all of the for loops is for the part wher i add things onto the file or var ;D ;D
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 10:38:22 PM
And what i am trying to do with this is get a list of all the files in a derectory (the one the batch file is in) and have only the files and no directories incluted and it needs to be in the bare format.
Title: Re: multipule lines as a var
Post by: GuruGary on June 29, 2006, 10:42:12 PM
I don't see anything that outputs to a file that is not commented out.  What is the problem with the script?  What is it doing, and what do you want it to do?
Title: Re: multipule lines as a var
Post by: GuruGary on June 29, 2006, 10:51:09 PM
Is there a reason you don't use the command:
Code: [Select]
dir /b /a-d
Or to save it to a file, use:
Code: [Select]
dir /b /a-d >testtt.txt
Or if you want the list in a semi-colon separated environment variable, use:
Code: [Select]
@echo off
set FileList=
for /f "delims=" %%a in ('dir /b /a-d') do call :AppendList %%a
echo FileList is: %FileList%
goto :EOF

:AppendList
set FileList=%FileList%;%1
goto :EOF
Title: Re: multipule lines as a var
Post by: GuruGary on June 29, 2006, 10:54:02 PM
For the "save to a file" method and then list them it would be like:
Code: [Select]
@echo off
dir /b /a-d >testtt.txt
echo List of files is:
type testtt.txt
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 10:54:24 PM
Ok i gust want to start freash. Could you make me a script that will get a list off all the files in a directory (not include the dirs) in bear format an output them to a file please.
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 10:54:57 PM
looks like i posted late lol
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 11:04:43 PM
OMG are you serus it is that easy i could never figer out what the - was for (prefix meaning not?????????) <--still dont get what that means but think you.
Title: Re: multipule lines as a var
Post by: ghostdog74 on June 29, 2006, 11:21:04 PM
Quote
OMG are you serus it is that easy i could never figer out what the - was for (prefix meaning not?????????) <--still dont get what that means but think you.
i suppose you are taking about dir /a-d ? check out dir /? .. it explains...
Code: [Select]

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               -  Prefix meaning not

"-" meaning not... so /a-d means display files, not directories...
Title: Re: multipule lines as a var
Post by: dakota on June 29, 2006, 11:43:14 PM
think you so much i have been working on this 4ever i cant beleav that all i needed was a simple - lol ok think you very very much.