Discussion:
help with piping - define variable with @select
(too old to reply)
NDog
2009-03-30 04:25:26 UTC
Permalink
I am trying to create a menu of all the *.t files in the directory,
and set the selected value as x

This works;
dir /b *.t > TEMP
set x=%@select[TEMP,1,1,10,10]
del TEMP

However if possible, could I simply put it in one line, that doesn't
rely on creating a temp file?
for example;
set x= dir /b *.t | %@select[CON,12,50,18,70,NRS3]
NDog
2009-03-30 04:52:38 UTC
Permalink
Post by NDog
I am trying to create a menu of all the *.t files in the directory,
and set the selected value as x
This works;
dir /b *.t > TEMP
del TEMP
However if possible, could I simply put it in one line, that doesn't
rely on creating a temp file?
for example;
never mind I finally found it in the search from this post in google
groups

http://groups.google.com/group/comp.os.msdos.4dos/browse_thread/thread/ea52ffd918f4dc35/322763bf09d416c2?hl=en&lnk=gst&q=set+with+piped+%40select+#322763bf09d416c2

dir /b *.t | set x=%@select[CON,12,50,18,70,NRS3]
- does what I want

Thanks
NDog
2009-03-30 05:22:03 UTC
Permalink
A more advanced question, that might not be possible on one line

directory listing of
1. *.btm
2. sorted by time last accessed
3. displaying filename - filedate - timeaccessed
4 into a @select menu
5. set x to the chosen value

theory code:
for /f %a in ('dir /b /O-D /T:a *.btm') do (
echo %@format[-12,%a] - %@filedate[%a,,2] - %@filetime[%a,w] )
| setx=@select[con,12,50,18,70,NRS3]

anyone?
NDog
2009-03-30 05:47:22 UTC
Permalink
Post by NDog
A more advanced question, that might not be possible on one line
directory listing of
1. *.btm
2. sorted by time last accessed
3. displaying filename - filedate - timeaccessed
5. set x to the chosen value
for /f %a in ('dir /b /O-D /T:a *.btm') do (
anyone?
I am sorry, since I am new to piping and the above code I posted
actually worked. As I am not used to | pipes, i didn't even test it
since, i thought the for loop would continuasly keep creating @slect
menu's (for every iteration of the loop) and didn't realise that the
whole output of that will be redirected to the | set x.

So I have posted the new code which does everything one one line. This
was possible by experimentation, and the correct post is actually this
one, which helped me

http://groups.google.com/group/comp.os.msdos.4dos/browse_thread/thread/2f81644b5649277f/68a7518e45508824?hl=en&lnk=gst&q=set+with+piped+%40select+#68a7518e45508824

Sorry,.. simple looking around and experimentation will work
eventually, although if anyone cares to elaborate on my code block I
am open to hear.

Thank you

working now;
for /f %a in ('dir /b /O-D /T:a *.btm') do (echo %@format[-12,%@left
[-4,%a]] - updated %@filedate[%a,,2] %@filetime[%a,w] ) | set x=%@word
[0,%@select[con,2,20,18,70,NRS3]].btm
Steve Fabian
2009-03-30 14:16:03 UTC
Permalink
NDog (1st post):
| However if possible, could I simply put it in one line, that doesn't
| rely on creating a temp file?
| for example;
| set x= dir /b *.t | %@select[CON,12,50,18,70,NRS3]

NDog wrote(3rd post):

| A more advanced question, that might not be possible on one line
| directory listing of
| 1. *.btm
| 2. sorted by time last accessed
| 3. displaying filename - filedate - timeaccessed
| 4 into a @select menu
| 5. set x to the chosen value

Ndog (4th post):
| working now;
| for /f %a in ('dir /b /O-D /T:a *.btm') do (echo %@format[-12,%@left
| [-4,%a]] - updated %@filedate[%a,,2] %@filetime[%a,w] ) | set x=%@word
| [0,%@select[con,2,20,18,70,NRS3]].btm


Please be careful to read how piping works in 4DOS. It actually creates a
temporary file, which is automatically deleted when the command is
completed, thus your approach does not meet the criterion you specified in
your OP (quoted above). If your sole purpose for piping is to eliminate the
need for manual deletion of the temporary file, your solution of that issue
is good. But beware: other command processors (e.g., 4nt, tcc, etc. - don't
know about CMD.EXE) may implement piping by the use of additonal instances
of the command processor, which have their own distinct set of environment
variables, thus an environment variable which is set on the right side of a
pipe dies unaccessibly when the command is completed.

Your real problem, however, may be different. What is your file system? If
it is a FAT variant (FAT32, VFAT), it does NOT save the time of day of last
access, only its date! Sorting by "last accessed" is by access date only.
Only if you use NTFS is the sorting as you intended.

There are other issues with your solution. Display is name, modification
date and modification time. This is what "updated" implies, but not what you
specified in the 3rd post. The name would be simpler using @NAME instead of
the @LEFT. @filetime does not require the 2nd parameter (,w) - it is the
default as it is for @filedate, where you explicitly skipped it. Lastly, the
word "updated" implies that the file is not in its original version (at
times the first version of a program actually performs its intended purpose,
so it is not "updated").
--
Steve
NDog
2009-04-01 07:36:15 UTC
Permalink
Post by Steve Fabian
| A more advanced question, that might not be possible on one line
| directory listing of
| 1. *.btm
| 2. sorted by time last accessed
| 3. displaying filename - filedate - timeaccessed
| 5. set x to the chosen value
| working now;
Please be careful to read how piping works in 4DOS. It actually creates a
temporary file, which is automatically deleted when the command is
completed, thus your approach does not meet the criterion you specified in
your OP (quoted above). If your sole purpose for piping is to eliminate the
need for manual deletion of the temporary file, your solution of that issue
is good. But beware: other command processors (e.g., 4nt, tcc, etc. - don't
know about CMD.EXE) may implement piping by the use of additonal instances
of the command processor, which have their own distinct set of environment
variables, thus an environment variable which is set on the right side of a
pipe dies unaccessibly when the command is completed.
Your real problem, however, may be different. What is your file system? If
it is a FAT variant (FAT32, VFAT), it does NOT save the time of day of last
access, only its date! Sorting by "last accessed" is by access date only.
Only if you use NTFS is the sorting as you intended.
There are other issues with your solution. Display is name, modification
date and modification time. This is what "updated" implies, but not what you
word "updated" implies that the file is not in its original version (at
times the first version of a program actually performs its intended purpose,
so it is not "updated").
--
Steve
Hi Steve, Thanks for your commenting and constructive criticism.

In the end I made a temp file, rather than piping to the @select
statement, because I had 2 parts of the script that needed to access
the temp file anyway, sheesh....

dir.tmp
test95 - updated 28/03/09 21:05
copyof~1 - updated 28/03/09 21:05

I would like to make a list that supports long file names, all FAT
versions, and NTFS, that shows the
- full file name
- date of file modifed
- time of file modified

It is confusing since I use FAT32 drives, NTFS drives, sometimes
networked drives, and the file time stamp seems to be inconsistant
across them, so in order I would like: filetime last accessed(yes),
filetime last modified,filetime created.

If you can help me to output a file that will look like this, I will
be so happy.
dir.tmp
test95 - updated 28/03/09 21:05
copy of test 95 - updated 28/03/09 21:05

I am using dos 7.10, 4dos 7.93, ntfs4dos

however that is a 'pipe dream' as there is no real-universal way of
getting lfn names in dos, so I will settle at 8.3 names

Hope that explains everything.
Steve Fabian
2009-04-01 14:00:03 UTC
Permalink
NDog wrote:
| I would like to make a list that supports long file names, all FAT
| versions, and NTFS, that shows the
| - full file name
| - date of file modifed
| - time of file modified
|
| It is confusing since I use FAT32 drives, NTFS drives, sometimes
| networked drives, and the file time stamp seems to be inconsistant
| across them, so in order I would like: filetime last accessed(yes),
| filetime last modified,filetime created.
|
| If you can help me to output a file that will look like this, I will
| be so happy.
| dir.tmp
| test95 - updated 28/03/09 21:05
| copy of test 95 - updated 28/03/09 21:05
|
| I am using dos 7.10, 4dos 7.93, ntfs4dos
|
| however that is a 'pipe dream' as there is no real-universal way of
| getting lfn names in dos, so I will settle at 8.3 names
|
| Hope that explains everything.

I would try something like this:

--- begin 4-line batch file ---
*dir/b/o-d/t:a *.btm > TEMP.CAT
do file in @TEMP.CAT
echo Accessed: %@filetime["%file",a] Updated: %@filedate["%file",,2]
%@filetime["%file"] %@filename[%@lfn["%file"]]
enddo
--- end 4-line batch file ---

Make sure the ECHO command is on a single line!

The reason to put the LFN last is to let the other fields line up
vertically. If that is not an issue, or if you know the maximum file name
size, you could put it first, possibly enclosing it in %@format[].

Some things to be aware:
1/ I use TCC (and occasionally older versions of 4NT) on my WinXP SP3
system, so I did not test this at all. I am not even sure what DOS 7.10 is
2/ Make sure that the original DIR command does not report any files both by
SFN and LFN.
3/ You could do all of this in a single PDIR command using TCC, or even the
free TCCLE if your real OS is at least WinXP
--
HTH, Steve
Loading...