0

i'm a completely new to this sort of thing, and have no idea where to start.

i'm trying to write a win 7 script for my boss, where the following happens;

  1. display a list of choices based on directories within a ftp directory
  2. when he selects one it will cd to that directory
  3. then display another list of choices based on files ending in .htm
  4. when he selects one it renames the first 8 characters with today's date yyyymmdd

all .htm files have a yyyymmdd format in the begining of the file name

what language should i use? any ideas where to start something like this?

edit: this is what i have so far

    echo off
    cls
    echo user me@company.com> ftpcmd.dat
    echo password>> ftpcmd.dat
    echo mls . 1.tmp>> ftpcmd.dat
    echo y >> ftpcmd.dat
    echo quit>> ftpcmd.dat
    ftp -n -s:ftpcmd.dat ftp.company.com
    del ftpcmd.dat

    type mls.tmp | more +2 > trim.tmp
    findstr /N "^" trim.tmp > dirs.tmp

    ::code need to make choices from dirs.tmp
    ::value of selected to be %dir%

    cls
    echo user me@company.com> ftpcmd.dat
    echo password>> ftpcmd.dat
    echo cd %dir%>> ftpcmd.dat
    echo mls . mls.tmp>> ftpcmd.dat
    echo y >> ftpcmd.dat
    echo quit>> ftpcmd.dat
    ftp -n -s:ftpcmd.dat ftp.company.com
    del ftpcmd.dat

    findstr ".htm" mls.tmp > trim.tmp
    findstr /N "^" trim.tmp > files.tmp

    ::code need to make choices from files.tmp
    ::value of selected to be %sel%

    set new=%date:~10,4%%date:~4,2%%date:~7,2%%sel:~9%

    cls
    echo user me@company.com> ftpcmd.dat
    echo password>> ftpcmd.dat
    echo cd %dir%>> ftpcmd.dat
    echo rename %sel% %new%>> ftpcmd.dat
    echo quit>> ftpcmd.dat
    ftp -n -s:ftpcmd.dat ftp.company.com
    del ftpcmd.dat
    del *.tmp

i firgured once i can fill in the missing pieces, i can loop it to cut down on the code.

4

1 回答 1

0

Ok, just test this for now and tell me if there are any problems.

Code:

echo off
setlocal enabledelayedexpansion
cls
echo user me@company.com> ftpcmd.dat
echo password>> ftpcmd.dat
echo mls . 1.tmp>> ftpcmd.dat
echo y >> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.company.com
del ftpcmd.dat

type mls.tmp | more +2 > trim.tmp
findstr /N "^" trim.tmp > dirs.tmp

:invalid
set count=0
Echo Directories:
Echo.
for /f %%a in (dirs.tmp) do (
set /a count+=1
Echo     !count!. %%a
)
Echo.
set /p "choice=Enter directory number: "
if "%choice%" equ "" (Echo Invalid Choice... &pause&cls&goto :invalid)
if %choice% lss "%count%" (Echo Invalid Choice... &pause&cls&goto :invalid)
if %choice% lss 0 (Echo Invalid Choice... &pause&cls&goto :invalid)

set count=0
set dir=null_value
for /f %%a in (dirs.tmp) do (
set /a count+=1
if !count!==!choice! set dir=%%a
)
cls
if "%dir%"=="null_value" (
Echo Error: direcotry finding
pause&Exit)
cls
Echo Selected %dir%
pause
cls
echo user me@company.com> ftpcmd.dat
echo password>> ftpcmd.dat
echo cd %dir%>> ftpcmd.dat
echo mls . mls.tmp>> ftpcmd.dat
echo y >> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.company.com
del ftpcmd.dat

findstr ".htm" mls.tmp > trim.tmp
findstr /N "^" trim.tmp > files.tmp

:invalid
set count=0
Echo files:
Echo.
for /f %%a in (files.tmp) do (
set /a count+=1
Echo     !count!. %%a
)
Echo.
set /p "choice=Enter file number: "
if "%choice%" equ "" (Echo Invalid Choice... &pause&cls&goto :invalid)
if %choice% lss "%count%" (Echo Invalid Choice... &pause&cls&goto :invalid)
if %choice% lss 0 (Echo Invalid Choice... &pause&cls&goto :invalid)

set count=0
set sel=null_value
for /f %%a in (files.tmp) do (
set /a count+=1
if !count!==!choice! set sel=%%a
)
cls
if "%sel%"=="null_value" (
Echo Error: File finding finding
pause&Exit)
cls
Echo Selected %sel%
pause
cls

set new=%date:~10,4%%date:~4,2%%date:~7,2%%sel:~9%

cls
echo user me@company.com> ftpcmd.dat
echo password>> ftpcmd.dat
echo cd %dir%>> ftpcmd.dat
echo rename %sel% %new%>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.company.com
del ftpcmd.dat
del *.tmp

There could be a lot of mistakes in that, but it should work. If it doesn't work, try running it in cmd as so:

  1. Start CMD
  2. Type Cmd.exe
  3. Drag and drop the batch file into the cmd window to run it from that directory

This way you will get an error message telling you whats wrong. If you do get one, tell me what it is and I can try fixing it for you.

Mona

于 2013-10-01T06:35:52.573 回答