Page 1 of 1 1
Topic Options
#206950 - 2013-03-25 12:13 PM File Copying and shell extensions
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
Hi

I am looking for a script to do some simple batch processing of files here is a summary

Check if any files exist in folder A
Take each file in folder A and run a shell command and the user file name

Top
#206951 - 2013-03-25 01:00 PM Re: File Copying and shell extensions [Re: GeorgeLittle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Hi George,

The article in the Script Vault titled "Central Data Collection - Kix as a Service" will do almost exactly what you want. It can even run as a system service.

That sample script runs continuously, monitoring a folder for a specific file type. When it finds it, it moves the file, reads it, and stores the contents in a CSV or INI file. So - 90% of the check & read is done for you.. just change what you want to do when the file is found.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206956 - 2013-03-25 03:13 PM Re: File Copying and shell extensions [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Glenn, you're either very perceptive...Or I am not at all. I read that post and sadly have no idea what he's wanting. Maybe I just need some more coffee.
Top
#206957 - 2013-03-25 03:23 PM Re: File Copying and shell extensions [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Maybe it's just the chills, fever, and 3 LARGE mugs of tea this morning! ;\)
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206959 - 2013-03-25 03:56 PM Re: File Copying and shell extensions [Re: ShaneEP]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: ShaneEP
I read that post and sadly have no idea what he's wanting.
I was doing OK until I got to the word "user" and then confusion set in.

Third cup of coffee didn't help.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#206960 - 2013-03-25 04:11 PM Re: File Copying and shell extensions [Re: Les]
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
Ok so I nearly have it working
 Code:
  Dim $_						; general purpose var
  Dim $_File						; working file name
  Dim $_Src						; source path to files

  $_Src = 'C:\cryptoin'				; where the client files are written

  $_ = RedirectOutput('c:\crypto_ftp_out')	; open the output file (different than collection folder!)

  ; look for files
  $_File = Dir($_Src + '\*.txt')			; read the first dir entry
  While Not @ERROR
$Crypto = $_File
$gpg = "gpg -o c:\crypto_ftp_out\$CRYPTO --encrypt ae7ca727 C:\cryptoin\$CRYPTO"
? $gpg
shell $gpg
    Del $_Src + '\' + $_File				; then delete the source file
    $_File = Dir()					; read the next dir entry & repeat until done
  Loop							; continue until done
  $_ = RedirectOutput('')				; Close the output redirection

  Exit 0

However the shell command does not output as expected never does the ? $gpg what have I done wrong this time ?


Edited by Mart (2013-03-25 04:39 PM)
Edit Reason: Please use code tags when posting code.

Top
#206961 - 2013-03-25 05:00 PM Re: File Copying and shell extensions [Re: GeorgeLittle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Try this slight change:
 Code:
  Dim $_						; general purpose var
  Dim $_File						; working file name
  Dim $_Src						; source path to files

  $_Src = 'C:\cryptoin\'				; where the client files are written


  ; look for files
  $_File = Dir($_Src + '*.txt')			; read the first dir entry
  While Not @ERROR
    $gpg = '%COMSPEC% /c gpg -o c:\crypto_ftp_out\' + $_File + ' --encrypt ae7ca727 ' + $_Src + $_File
  $gpg ? ; DEBUG LINE
    shell $gpg
    Del $_Src + $_File				; then delete the source file
    $_File = Dir()					; read the next dir entry & repeat until done
  Loop							; continue until done

  Exit 0
There's no reason to set $_File to $CRYPTO (redundant) and you should not put the var inside the string. Also, no need to RedirectOutput because it seems that your gpg command string is writing to the destination folder.

I'd also check the result of the Shell command and only delete the file if the command was successful. I'd move the original file to a FAILED folder if the command did not succeed.

Glenn

_________________________
Actually I am a Rocket Scientist! \:D

Top
#206963 - 2013-03-25 06:10 PM Re: File Copying and shell extensions [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would say there is no way to make it work with redirectoutput() like it was.
you are basically saying the output will be a file c:\crypto_ftp_out and then while that file is still open in kixtart, you are trying to tell operating system that it is a folder instead.
so, if the folder is not there, kixtart makes it a file and no output can be done to a folder with the same name. if it is there as a folder, redirectoutput will fail.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.063 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org