Computer Hope
Microsoft => Microsoft DOS => Topic started by: slackhouse on September 15, 2008, 01:29:49 PM
-
I've written a basic batch file to read a directory and output all the files into another .txt. file.
@echo off
cd C:\Production Change Actions\Input
dir /b > "C:\Documents and Settings\username\Desktop\Imports.txt"
I'm now trying to get all of those file names placed into this line of another batch file.
@echo off
cls
:start
cd C:\Program Files\Thunderhead35
Thunderhead.Importer.exe -user DPS\username -conflict overwrite -verbose -file
INSERT FILE NAME FROM IMPORTS.ZIP
The file names have to be placed into the second batch file individually and the Thunderhead.Importer.exe does not allow "*.zip" for me to do them all at once. So, I'll need the batch to be able to read each line, insert it into the second batch, then have the batch file run, then start over all the way through all of the file names.
-
what actually are you wanting to do?
-
This should work:
@echo off
cd /d C:\Program Files\Thunderhead35
for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
Thunderhead.Importer.exe -user DPS\%username% -conflict overwrite -verbose -file "%%v"
)
Double check username. Wasn't sure if that is a literal or the system variable.
8)
-
thanks...i'm gonna try that out. The "username" is a specific username that I'll change it to. I just changed it to username for privacy. I'll let you know how this works in a little while.
-
Okay...I got it to work...I had to make a minor change in order to get it to read the file correctly:
@echo off
cd /d C:\Program Files\Thunderhead35
pause
for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
Thunderhead.Importer.exe -user domain\username-conflict overwrite -verbose -file [b]C:\Production Change Actions\Input\\[/b]"%%v"
)
pause
without adding that part, it kept saying, "cannot find C:\Program Files\Thunderhead35\whateverthefilename.zip" And, I had to add in two slashes to get it to read correctly.
Thanks for the help!!! Is their anything wrong with the way I tweaked it?
-
Is their anything wrong with the way I tweaked it?
Not a thing. Any tweak that works is a good tweak. ;D
-
@echo off
cd /d C:\Program Files\Thunderhead35
pause
for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
Thunderhead.Importer.exe -user domain\username-conflict overwrite -verbose -file C:\Production Change Actions\Input\\"%%v"
)
pause
Could you explain what some of this actually means?
I guess the for and do are where I'm lost on what this is actually doing.
Tokens=*???
delims=nothing???
why is the variable %%v???
I'd like to understand this so I don't have to ask a similar question later. Thanks.
-
tokens=*
tokens=2* defines 3 variables (tokens)
tokens=1* defines 2 variables
tokens=* defines 1 variable
Could I have used tokens=1? Yes! Go figure!
delims=nothing
the default delimiters are tab and space; overriding with no delimiters avoids dropping data when file names have embedded spaces
why is the variable %%v??? Why not? ;D The variable declared can be any lower or upper case letter. Numerics can be used, but are easily confused with command line arguments.
Using the tokens=, delims= and the declared variable, each for statement is constructed specific to the data.
The for command is highly nuanced. These sites are much more eloquent than I could be.
Iterating with FOR (http://commandwindows.com/batchfiles-iterating.htm)
FOR (http://technet.microsoft.com/en-us/library/bb490909.aspx)
8)
-
Thank you for your assistance. It is greatly appreciated.