Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Batch file suggestions?
Message
De
25/05/2006 20:07:36
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
 
 
À
25/05/2006 16:15:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows 2000 SP4
Divers
Thread ID:
01125021
Message ID:
01125122
Vues:
15
>Have you checked out the HELP on the FOR command? There seems to be some options available (beyond what was available in DOS) that could come in handy.
>
>Maybe something like this (haven't tested this)?
>
>@ECHO OFF
>DIR /B /OD LPT$VPN.* > C:\TMP\MYLIST.TXT
>SET LastF=
>FOR /F %%i IN (C:\TMP\MYLIST.TXT) DO SET LastF=%%i
>IF [%LastF%]==[] GOTO Quit
>FOR /F %%i IN (C:\TMP\MYLIST.TXT) DO IF NOT [%%i]==[%LastF%] DEL %%i
>SET LastF=
>:Quit
>DEL C:\TMP\MYLIST.TXT
>
The FOR /F was key, as you suggested. I reduced it to the following (8 commands in total, only 2 are really necessary):
@ECHO OFF

REM Set the wildcard string of the files to be deleted:
set FileWild="LPT$VPN.???"

REM Set the value below for the "n" MOST RECENT files to be NOT deleted (i.e. skipped):
REM set /?
REM http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/set.mspx?mfr=true
set /a NumSkip="2"

REM This command writes all files matching the wildcard string to FileList.txt
REM in REVERSE DATE ORDER, i.e. most recent at the top:
REM dir /?
dir %FileWild% /o-d /b >FileList.txt

REM This command parses the FileList.txt file line-by-line
REM for /?
REM http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx?mfr=true
REM /F instructs the for command to parse
REM "skip=%NumSkip%" to skip the first NumSkip lines
REM (so those files won't be processed i.e. deleted):
for /F "skip=%NumSkip%" %%I in (filelist.txt) do erase %%I

REM Cleanup:
erase FileList.txt
set NumSkip=
set FileWild=
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform