|
Answer» Hello again. I'm reposting this question a little clearer to hopefully remove some of the confusion about it.
What I am trying to do is make a batch that will check a directory for the newest folder in it (I already have this part) and then determine what the next sequence will be. For example, there are 3 folders in the directory, FCO10122, FCO10123, FCO10124. The FCO101 part will remain static, never changing. The last 2 digits will continue to ascend up to 99 and then loop back to 00. I need a batch that will seperate the last 2 digits from the folder name and add 1 to it to determine the next sequence number.
Once that is accomplished, I then want to only allow that sequence number to be sent to the directory, giving an error for any other one attempted to be sent. Here's the code I have thus far, with no attempt at determining the sequence number or only allowing the next one.
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 echo The most recent Data Transfer on file is: "%newest%" 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" )
The last part here simply creates a folder in the directory with the same name as the file and moves the files to that folder. Here is where I want to insert an error code if the sequence number is incorrect.
For determining the next sequence number, I have tried doing a set /a and ADDING 1 to the newest folder name, but since the folder name is alpha-numeric the math does not work and I simply END up with 1. This is why I need to seperate the last 2 digits from the folder name, so I can add 1 to it.
Everything I have in my code above is correct and works like a dream, I just need to build on it.
Thanks.set lasttwo=%newest:~6%
cut the first 6 digits from the variable newest and sets the rest in the variable lasttwo. Which Windows do you have? In Versions since W2k it should also be possible to extract the last two. Would be more elegant.
hope it helps uli
It's Win2k
Sorry, forgot to mention that.
But it did work just need to figure out how to allow only that one to transfer now. I'm absolutely no good with IF and ERRORLEVEL commands
This is the beginning where I determine which sequence number I need: 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 lasttwo=%newest:~6% set /a next=%lasttwo%+1 echo The Data Transfer EXPECTED is: FCO101%next% pause OK, what I need to do now is set an IF command so that if the file in the B:\ is the correct sequence number it can continue with the data move. Say the last one in the directory was FCO10135 and I should now be expecting FCO10136. So if FCO101%next%.A01 is = B:\*.A01 all is well. (%next% being my last two #'s +1) If the file in B:\ is NOT the one I am expecting I just want to give an echo prompt.
There are several ways to get the file name from b:\*.A01. The command I have set for the move is: Code: [Select]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" )
So If there is a way to set %%i before the IF command, things could be simpler. I just do not know the proper sequence of commands and ()'s and ""'s etc etc to do this.Well, I did a IF /? and tried to decipher it enough to make it work. 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 lasttwo=%newest:~6% set /a next=%lasttwo%+1 echo The Data Transfer expected is: FCO101%next% pause if [/i] "FCO101%next%.A01" equ ('dir /b b:\*.A01') do ( 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" ) echo Data Transfer Completed sucessfully ( pause ) ) else ( echo THIS IS NOT THE CORRECT SEND NUMBER! WE ARE EXPECTING FCO101%next% Please go back into ULLS-A and send the correct one. ) pause
But.... it doesn't work. It just ends after the first pause where it displays the echo of FCO101%next% The whole IF command doesn't work lol. Please help me on this, as those of you who know what you're doing can probably see by my jacked up code here I'm not real snazzy on this stuff.
Thanks.I figured it out
Here's the finished product of my if command. I set the transferring part to a different batch and used the call command in the IF line. Works like a charm. (the astute among you will notice a change in directories, that's cause it's out of the test bed COMPUTER and I'm trying it on the network.)
Code: [Select]@echo off for /f "delims=" %%a in ('dir /od /b "\\ullsapcwdyfd0\acftsends\big windy\101"') do set newest=%%a set lasttwo=%newest:~6% set /a next=%lasttwo%+1 echo The Data Transfer expected is: FCO101%next% pause for /f "tokens=1-2 delims=." %%t in ('dir /b b:\*.a01') do set current=%%t echo You are trying to send %current% pause if FCO101%next% equ %current% ( color a0 call c:\send.bat ) else ( color 40 echo THIS IS NOT THE CORRECT SEND NUMBER! WE ARE EXPECTING FCO101%next% PLEASE SEND THE CORRECT ONE. pause )
I even color coded it for the idiots that refuse to read the messages
My next problem is the looping from 99 to 00. I had a response to this on my last thread, but I"m not sure I understand it.
GuruGary, can you please tell me if both of these lines have to be in the code or just one, and where in rest of the code the code would it go? Quote 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% Thanks.Ok, nevermind on that as well, I fiddled with it and worked it
Thanks again guys. This is gonna help a LOT.
For those interested, here's the final code:
Code: [Select]@echo off for /f "delims=" %%a in ('dir /od /b "\\ullsapcwdyfd0\acftsends\big windy\101"') do set newest=%%a set lasttwo=%newest:~6% set /a next=%lasttwo%+1 if %next% GEQ 100 set /a next-=100 if %next% LEQ 9 set next=0%next% echo The Data Transfer expected is: FCO101%next% pause for /f "tokens=1-2 delims=." %%t in ('dir /b b:\*.a01') do set current=%%t echo You are trying to send %current% pause if FCO101%next% equ %current% ( color a0 call c:\send.bat ) else ( color 40 echo THIS IS NOT THE CORRECT SEND NUMBER! WE ARE EXPECTING FCO101%next% PLEASE SEND THE CORRECT ONE. pause )
With send.bat being:
Code: [Select]@echo off for /f "tokens=1-2 delims=." %%i in ('dir /b b:\*.a01') do ( md "\\ullsapcwdyfd0\acftsends\big windy\101\%%i" copy b:\*.* "\\ullsapcwdyfd0\acftsends\big windy\101\%%i" ) PAUSE
Works like a champ
|