Home All Groups Group Topic Archive Search About

Script to parse programatically through files in a folder



Author
17 Nov 2007 8:56 PM
Hassan
I am new to scripting and even programming for that matter..

What i want to do is run a command that processes all files in a folder and
once successfully done move the processed file to another folder

So for eg:

Right now, i want to run this

C:\command1.exe c:\folder1\file1.txt

My folder1 contants many files in it such as file1.txt,file2.txt,etc.. And i
want to process all these files. It would appear that these file names are
passed as parameters to that command file command1.exe

Once I process file1 successfully, I want to move it to c:\successfularchive

Can you provide a template for me to use ? I would so appreciate it.

Thanks

Author
18 Nov 2007 12:06 PM
Michael Bednarek
On Sat, 17 Nov 2007 12:56:58 -0800, Hassan wrote in
microsoft.public.windows.server.scripting:

Show quote
>I am new to scripting and even programming for that matter..
>
>What i want to do is run a command that processes all files in a folder and
>once successfully done move the processed file to another folder
>
>So for eg:
>
>Right now, i want to run this
>
>C:\command1.exe c:\folder1\file1.txt
>
>My folder1 contants many files in it such as file1.txt,file2.txt,etc.. And i
>want to process all these files. It would appear that these file names are
>passed as parameters to that command file command1.exe
>
>Once I process file1 successfully, I want to move it to c:\successfularchive
>
>Can you provide a template for me to use ? I would so appreciate it.

Look at the output of FOR /? from cmd.exe, or type this in your
Start/Run box: ms-its:%WINDIR%\help\ntcmds.chm::/for.htm

--
Michael Bednarek   http://mbednarek.com/   "POST NO BILLS"
Author
19 Nov 2007 3:44 AM
Al Dunbar
Show quote
"Michael Bednarek" <mbATmbednarek.com@BLACKHOLESPAM.NET> wrote in message
news:6fa0k3drphabf9boqajouud0cfsk92ufui@4ax.com...
> On Sat, 17 Nov 2007 12:56:58 -0800, Hassan wrote in
> microsoft.public.windows.server.scripting:
>
>>I am new to scripting and even programming for that matter..
>>
>>What i want to do is run a command that processes all files in a folder
>>and
>>once successfully done move the processed file to another folder
>>
>>So for eg:
>>
>>Right now, i want to run this
>>
>>C:\command1.exe c:\folder1\file1.txt
>>
>>My folder1 contants many files in it such as file1.txt,file2.txt,etc.. And
>>i
>>want to process all these files. It would appear that these file names are
>>passed as parameters to that command file command1.exe
>>
>>Once I process file1 successfully, I want to move it to
>>c:\successfularchive
>>
>>Can you provide a template for me to use ? I would so appreciate it.
>
> Look at the output of FOR /? from cmd.exe, or type this in your
> Start/Run box: ms-its:%WINDIR%\help\ntcmds.chm::/for.htm

The only issue I see here is how to determine that each file processed was
processed *successfully*. Perhaps the .exe will indicate failure with a
non-zero return code. Or perhaps it creates an error log file to put error
messages in if something went wrong. Anyway, assuming the non-zero error
code, try something like this in a batch file:

    setlocal enabledelayedexpansion
    for %%F in (C:\folder1\*.txt) do (
        C:\command1.exe %%F
        if errorlevel 1 (
            echo/error encountered on file %%F & pause
        ) else (
            move %%F C:\successfularchive
        )
    )

/Al

AddThis Social Bookmark Button