|
Answer» Hi,
I'm trying to set up a variable based on the content of a dir listing on an FTP site. Basically, just want the variable to be the name of the file contained on the site, which will be changing daily. I have tried outputting the dir listing to a txt file, but can't figure out how to get the contents of that file into a variable.
Any ideas???I'm unsure what you mean by putting the contents of a directory listing into a variable. If you need the label of one file in the dir LIST put into a variable, you can TRY this:
Note this works in batch file only.
for /f %%a in ('dir /b ^| find "zzzzz"') do set var=%%a
You will have to filter the dir commmand or change the zzzzz to something that is unique about the file label (perhaps the extension).
The above is just to give you something to think about, not a working solution.
Hope this helps. Guess I wasn't very clear sorry.
Here is what I am trying to accomplish, in batch: Connect to an FTP site There will be a file, which has a different number stamped on it each day. I want this filename on the remote site to be put into a variable in my batch.
So, for example, on this site is a file named myfile1234.dat. I would want to have a variable set to myfile1234.dat.
I have tried "dir myfile*.dat > ftpdir.tmp" which gives me the listing in a file, but is there anyway to then get the data out of that file and into a var?Quote I have tried "dir myfile*.dat > ftpdir.tmp" which gives me the listing in a file, but is there anyway to then get the data out of that file and into a var?
Not REALLY, but if the dir list contains only one .dat file, you can isolate it and then set the variable.
for /f %%a in ("dir /b myfile*.dat") do set var=%%a
The problem arises if there is more than one .dat file. If you could get the dir list in some sort of sequence and guarantee that the .dat file is always last in the list, you can loop the set command over the entire list. The var would then have the value of the last file.
You could ALSO consider how the file label was generated in the first place and then use the same method to generate the var value.
Guess I can't be clear enough...
What I was looking for: for /F "tokens=9* " %%i in (ftpdir.tmp) do set datafile=%%i
this sets the variable "datafile" to whatever the name of the file is that resides on the ftp server and has been echoed out to a tmp file.
thanks.
|