|
Answer» Hello again. I want to know how to do a dir command that will only display the newest file/folder in the directory. It could also be done by the highest number since the folders are named xxxxx## in ascending order. Either way would work.
Thanks in advance While waiting for some arcane solution, use this DIR /OD then just look at the bottom of the list.
DIR /ON if you want by name
MacAnybody? Beuler? Beuler?
C'mon, surely there's a way to do this.ok, try this Graham Code: [Select]>$temp$ Dir /O-D SET /P MyFile=<$temp$ Del $temp$ Echo %MyFile%hmm that doesnt work, the parent directory is always at the top of the list someone else ? GrahamTry this: Code: [Select]@echo off for /f "delims=" %%a in ('dir /od /b') do set newest=%%a echo Newest is "%newest%"Thanks
That is what I was looking for.
For my next stumper (lol) .......
I am an administrator on an obsolete Sage database. This fossil sends data to and from standalone laptops to a network via sequenced data transfers. I cannot receive, say FCO10156, before I receive FCO10155. The first 3 numbers are tail numbers for an aircraft and will remain static. The last 2 are the sequence numbers. I have a BIG problem of people making data transfers and not sending it, then making and sending the next one out of sequence. My goal here is to make a batch file that, before sending the data transfer, will check to make sure it is the proper sequence number. I already have the sending part down. The batch file (that was made thanks to this forum ) takes the file from their emulated A:\ or B:\ (ya, it requires a floppy drive so I subistuted it with a MSRAMDRIVE) and makes a folder on my computer in a specified location named XXXXXX## (again, the X's are static and the #'s are the ascending sequence numbers) and places the files into that folder. What I want to do is make the batch file display the data transfer that I am expecting and only allow that one to be transfered. I already have the answer to finding the newest file in the directory, now I need it to add 1 to the ## (LOOPING from 99 to 00) and display that, then allow only that sequence number to be sent.
This is what I have thus far. Code: [Select]@echo off cd "C:\Documents and Settings\Administrator\Desktop\sends\101" for /f "delims=" %%a in ('dir /od /b') do set newest=%%a set /a transfer="%newest%+1" echo The Data Transfer expected is: "%transfer%" pause for /f "tokens=1-2 delims=." %%i in ('dir /b b:\*.a01') do ( md "C:\Documents and Settings\Administrator\Desktop\sends\101\%%i" COPY b:\*.* "C:\Documents and Settings\Administrator\Desktop\sends\101\%%i" )
[size=20] I understand that the following part is incorrect: [/size] Code: [Select] set /a transfer="%newest%+1" echo The Data Transfer expected is: "%transfer%" This is what I am trying to figure out, that and allowing only %transfer% to be sent in the 2ND part, where it actually sends the files.
Complicated, I know, but it is the biggest headache in the world trying to keep this ancient program up to date with the latest information.
Thanks in advanceI'm not sure I understand what you want.
For the "looping from 99 to 00" you can do: Code: [Select]if %transfer% GEQ 100 set /a transfer-=100... but if it always needs to be 2 digits ("00" instead of "0") then you need an additional line of code anyway, like: Code: [Select]if %transfer% LEQ 9 set transfer=0%transfer% I'm not sure what you are looking for here Quote [size=20] I understand that the following part is incorrect: [/size] Code: [Select] set /a transfer="%newest%+1" echo The Data Transfer expected is: "%transfer%"
Try to explain the steps of what you want to do, or what you are trying to accomplish, and I'll help you convert those steps to code.Ok. The name of the folder in question is FCO101## with ## being the sequence number. I want this batch to determine the next sequence number I am expecting by looking at the newest one in the directory and adding 1 to the sequence number. I have the idea that I need to do a set /a to add one, but since the folder is alphanumeric DOS does not see it as a number, therefore adding +1 to the folder name just gives me 1. I need to seperate the ## from the folder name so I can add 1 to it. I know it has to do with setting delims and tokens, but I just don't speak the language well enough to figure it out.
Hope that clarifies it enough. Thanks^^ bump.
|