# Batch file help please!!!!



## canadninan (Apr 5, 2006)

Can anyone please please help me on this?
The batch file needs to do the following:

1. Asks user if she has entered any excel documents or if there is a deadline in progress 
a. If yes, give a warning line and do nothing else 
b. If no, proceed to move the files 
2. The files to be moved are located in the following folder 
D:\spreadsheets\Data

3. Move the files to a temporary folder and rename them to the date they were moved and the original file name (e.g. the file named 02PYA deleted on April 3, 2006 would be moved and renamed to 040306_02PYA) 

4. After the files have been moved alert the user and end the program. Have the user manually close the DOS window once the program has completed


----------



## canadninan (Apr 5, 2006)

Can anyone please please help me on this?
The batch file needs to do the following:

1. Asks user if she has entered any excel documents or if there is a deadline in progress 
a. If yes, give a warning line and do nothing else 
b. If no, proceed to move the files 
2. The files to be moved are located in the following folder 
D:\spreadsheets\Data

3. Move the files to a temporary folder and rename them to the date they were moved and the original file name (e.g. the file named 02PYA deleted on April 3, 2006 would be moved and renamed to 040306_02PYA) 

4. After the files have been moved alert the user and end the program. Have the user manually close the DOS window once the program has completed


----------



## draceplace (Jun 8, 2001)

This site has a lot of bat files you can look at...

http://www.robvanderwoude.com/index.html


----------



## gophersnake (Mar 5, 2006)

It's been a while since I worked with DOS batch files but if memory serves...

_1. Asks user if she has entered any excel documents or if there is a deadline in progress
a. If yes, give a warning line and do nothing else
b. If no, proceed to move the files _

... a batch file can't do this by itself. The way this had to be done was by running some other program that would ask the question, get the user's answer, and turn the answer into a "return code". Suppose we're doing it in assembly language, we have the user's answer, and we've saved it in the byte-sized variable RETCODE. Then:

```
MOV AH, 4CH
MOV AL, RETCODE
INT 21H
```
The program would terminate and return control to the batch file. Back in the batch file, we could now test for the value of the return code, which the batch file would access as ERRORLEVEL:

```
IF ERRORLEVEL 2 GOTO NOUDONT
IF ERRORLEVEL 1 GOTO FILECOPY
GOTO DONE
```
_3. Move the files to a temporary folder and rename them to the date they were moved and the original file name (e.g. the file named 02PYA deleted on April 3, 2006 would be moved and renamed to 040306_02PYA)_

I know of no way that a batch file can read the timestamp on a file or edit the date information into a filename. If I had to do that, I'd consider programming it either in assembler or in something like Foxpro.

Your example, "040306_02PYA", would have to be a Windows-style "long" filename. The DOS versions that are part of Windows do seem to rename files to long filenames if you put the filename in quotes, something like this:

```
ren 02PYA.xls "040306_02PYA.xls"
```


----------



## lycos5 (Mar 10, 2006)

you can also try qbasic but I'm not sure it can do all you're asking for


----------



## dtech10 (Jan 31, 2003)

Hi Canadninan
What Operating are you using.


----------



## JohnWill (Oct 19, 2002)

I suspect if you check these DOS utilities, you'll find more than enough free batch file enhancers to accomplish the mission: Garbo Batch Utilities.


----------



## cybertech (Apr 16, 2002)

Threads merged.


----------



## canadninan (Apr 5, 2006)

I am using Windows 2000


----------



## JohnWill (Oct 19, 2002)

Many (most?) of the batch enhancers will still work under Windows.

For Windows automation, I use AutoIt, you can almost program a whole application with it, but simple jobs are simple to build too.


----------



## dtech10 (Jan 31, 2003)

Hi
This works ok in WinXP
might work in Win2000, the date format is dd/mm/yy
Not very elegant but might help


@echo off
rem default to y, delete if not required
set Answer=y
for /f "tokens=1-3 delims=/-" %%a in ('date /t') do (
set Day=%%a
set Mth=%%b
set Yr=%%c
)
set Yr=%Yr:~2,2%
echo Any Excel Documents or Deadline in Progress
set /p Answer=
if "%answer%"=="y" (echo Warning
) else ( dir /b /a-d d:\spreadsheets\data\*.* > Files.txt
for /f %%a in (Files.txt) do move %%a d:\Temp\%%~na_%Day%%Mth%%yr%%%~xa )


----------



## blaqDeaph (Nov 22, 2005)

gophersnake said:


> The program would terminate and return control to the batch file. Back in the batch file, we could now test for the value of the return code, which the batch file would access as ERRORLEVEL:


Thats really cool. So what DOS sees as ERRORLEVEL is actually AL? That would only apply to 16bit architecture right?


----------



## gophersnake (Mar 5, 2006)

*(blaqDeaph):* _So what DOS sees as ERRORLEVEL is actually AL?_

Yes. Not the current AL, of course. ERRORLEVEL gets set to whatever the last program put in AL before it exited with INT 21H Function 4CH.

If I were going to test ERRORLEVEL I'd do it right away because I'm not sure what else, if anything, could eventually change it.

I've only programmed in Real Mode myself but I did find this reference to doing something similar in Protected Mode: Client Termination. It sounds complicated as hell. I guess that's what high-level languages are supposed to spare us from.


----------

