Batch job for deletion of flat files

niteshnavniteshnav Member Posts: 35
We have the sales information imported from the local native dbs to the HQ(Retail enrnmnt). The folder size gets heavy. Can there be an automatic batch job in navision or windows, which can run to delete old files?

Comments

  • krikikriki Member, Moderator Posts: 9,118
    Yes, use the file-virtual table in Navision. On the forum you will find information on how to use it.
    You can run the routine with NAS or after a certain dataport has been run.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • niteshnavniteshnav Member Posts: 35
    I meant, information stored in the form of flat files. The flat files get stored in the system everytime it imports occupying lot of space. Do u mean to delete such files i can use fil-virtual table to execute through NAS?

    regards,
    Nitesh
  • krikikriki Member, Moderator Posts: 9,118
    Yes,

    with the virtual table "file" you can find files in a certain directory.
    With a REPEAT UNTIL on the table, you can ERASE them 1 by 1.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi,

    Assuming that temporary files are generated in one place wouldn't be much faster to use SHELL('cmd.exe', '/c', 'del /Q /F drive:\path\*.*') instead of deleting files one by one ?

    BTW: I remember in the old DOS time :) there was some simple utility to clean disk: killdir.exe. It was really FAST.

    Regards,
    Slawek Guzek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • krikikriki Member, Moderator Posts: 9,118
    Assuming that temporary files are generated in one place wouldn't be much faster to use SHELL('cmd.exe', '/c', 'del /Q /F drive:\path\*.*') instead of deleting files one by one ?
    Yes it is faster, but if you want only to delete the older files, you cannot use it (or if you can recognize the older files on the name, you might be able to do it).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mploschiavomploschiavo Member Posts: 6
    i pulled this off experts-exchange.com

    Try this:

    @echo off

    setlocal

    REM You can pass the source directory on the command line
    set srcDir=.
    if not "%~1"=="" set srcDir=%~1

    REM Set file mask, defaults to all files
    set dirMask=

    REM To enable subdirectory processing set this to /s
    set subDir=

    call :GETPARTS "%date%

    call :SUBTRACTDAYS 32

    set cutoffDate=%yy%/%mm%/%dd%

    pushd.

    cd /D %srcDir%

    for /f "delims=" %%a in ('dir %subDirs% /b /a-d %dirMask%') do call :PROCESS "%%a" %%~ta

    popd

    goto :EOF

    :PROCESS

    call :GETPARTS %2

    REM ** Remove echo from the statement below to enable the actual delete
    if /i "%cutoffDate%" GTR "%yy%/%mm%/%dd%" echo del /F %1

    goto :EOF

    :SUBTRACTDAYS

    set dayCnt=%1

    if "%dayCnt%"=="" set dayCnt=1

    REM Substract your days here
    set /A dd=1%dd% - 100 - %dayCnt%
    set /A mm=1%mm% - 100

    :CHKDAY

    if /I %dd% GTR 0 goto DONESUBTRACT

    set /A mm=%mm% - 1

    if /I %mm% GTR 0 goto ADJUSTDAY

    set /A mm=12
    set /A yy=%yy% - 1

    :ADJUSTDAY

    if %mm%==1 goto SET31
    if %mm%==2 goto LEAPCHK
    if %mm%==3 goto SET31
    if %mm%==4 goto SET30
    if %mm%==5 goto SET31
    if %mm%==6 goto SET30
    if %mm%==7 goto SET31
    if %mm%==8 goto SET31
    if %mm%==9 goto SET30
    if %mm%==10 goto SET31
    if %mm%==11 goto SET30
    REM ** Month 12 falls through

    :SET31

    set /A dd=31 + %dd%

    goto CHKDAY

    :SET30

    set /A dd=30 + %dd%

    goto CHKDAY

    :LEAPCHK

    set /A tt=%yy% %% 4

    if not %tt%==0 goto SET28

    set /A tt=%yy% %% 100

    if not %tt%==0 goto SET29

    set /A tt=%yy% %% 400

    if %tt%==0 goto SET29

    :SET28

    set /A dd=28 + %dd%

    goto CHKDAY

    :SET29

    set /A dd=29 + %dd%

    goto CHKDAY

    :DONESUBTRACT

    if /I %mm% LSS 10 set mm=0%mm%
    if /I %dd% LSS 10 set dd=0%dd%

    goto :EOF

    :GETPARTS

    set dt=%~1
    set tok=1-3

    if "%dt:~0,1%" GTR "9" set tok=2-4

    set yyyy=

    for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
    for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
    )

    if not "%yyyy%"=="" set yy=%yyyy%

    if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
    if 1%mm% LSS 100 set mm=0%mm%
    if 1%dd% LSS 100 set dd=0%dd%

    goto :EOF

    I've disabled the actual deleting of the files by placing an echo statement prior to the del command. It's marked in the file.

    Also, read the comments at the top for customization options.

    Good Luck,
    Steve

    Accepted Answer from For-Soft
    Date: 03/16/2006 05:31AM PST
    Grade: A
    Accepted Answer


    What about XCOPY with file list /L command?
    xcopy /L /S /D:13-01-2006 c:\somedir\*.*

    Comment from PaulCaswell
    Date: 03/16/2006 03:31PM PST
    Comment


    Hi IUAATech,

    Do you mean real 16bit dos or command window dos?

    Would you accept a shareware tool?

    Paul

    Comment from PaulCaswell
    Date: 03/16/2006 04:27PM PST
    Comment


    Hi IUAATech,

    If 16bits is not required, try:

    http://uk.geocities.com/xshareware/Download/XDir.zip

    There's even an example in the manual for deleting files older than a certain number of days. Let me know if you like it? I wrote it myself! Theres no time limit and no crippling, just a one-liner nag on-screen at launch time.

    Paul

    Assisted Answer from PaulCaswell
    Date: 03/22/2006 10:30AM PST
    Grade: A
    Assisted Answer


    Hi IUAATech,

    Actually, the link is now:


    http://uk.geocities.com/xshareware/download/xdir.zip
  • CtrlShiftF11CtrlShiftF11 Member Posts: 29
    Guys, why not write some code using the EXISTS and ERASE commands. Navision handles this stuff very well for me when I'm working with custom programs that I've written to import, export or just plain handle flat files. You should make your own personal function library to handle this so that you can pass arguments at runtime to make it reusable.

    Good Luck,
    Andy Sandefer
    \:D/
Sign In or Register to comment.