Focal Point
Deleting a file from a folder according to a pattern.

This topic can be found at:
http://forums.informationbuilders.com/eve/forums/a/tpc/f/1381057331/m/8987030016

September 21, 2011, 10:47 AM
Gopal_mys
Deleting a file from a folder according to a pattern.
Hi,

I have a folder A which has files like below

File1.txt
File1z.txt
File2z.txt
File3z.txt

How do I delete the files which has a pattern which ends with z.txt and leaving other files as it is.

I tried using the File object with a pattern *z.txt ..
It didn't work..
Is there any other way to acheive this.

Thanks


iWay ISM 5.5/iWay ISM 6.0 on Windows.
September 21, 2011, 05:41 PM
Waz
Can you post the actual code you used, also where are the files, and what happened when you used the code, did it delete all the files, or none, or some ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

September 22, 2011, 08:24 AM
Gopal_mys
Hi Waz,



I have the above mentioned files in the path that i have used in the properties and I just built a pflow which includes this FILE(FileOperations)object and ran in the designer,
It runs successfully,but it didn't delete the files.

Thanks


iWay ISM 5.5/iWay ISM 6.0 on Windows.
September 22, 2011, 05:35 PM
Waz
Don't know if I can help much, not an iWay person.

Does the documentation say that wildcards are supported ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

September 23, 2011, 06:29 AM
AdeH
Hi Gopal,
I suspect that File (from) doesn't accept wild cards. I'm not certain, and can't find anything in the doco.

Have you tried the XDRunCmdAgent? You can issue any command line command from a service object using this. Search info centre for 'run command agent' for details.

Regards,
Ade


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
September 23, 2011, 10:56 AM
AdeH
I should probably say, you can issue a command to the server command line with this agent, so you could issue:

del D:\XX_Gopal\GK\FilesDelete\*z.txt

and interrogate the return codes passed back from the agent afterwards...


Ade.


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
September 25, 2011, 06:03 AM
Gopal_mys
Thanks for the reply AdeH,

But when I execute a simple p-flow with the service XDRunCmdAgent and with the command mentioned by you
del D:\XX_Gopal\GK\FilesDelete\*z.txt,

P-flow fails to execute with the error,
error : Detected problem in agent execute: java.io.IOException: CreateProcess: del D:\XX_Gopal\GK\FilesDelete\*z.txt error=2


iWay ISM 5.5/iWay ISM 6.0 on Windows.
September 26, 2011, 04:55 AM
AdeH
Hi Gopal,
This works fine for me if I use an SREG to hold the command I'm issuing... set an SREG to have the value:
del D:\XX_Gopal\GK\FilesDelete\*z.txt

Then reference that SREG in your XDRunCmdAgent property runcmd.cmd.label. I left all other properties of the agent as default - platform, false, false, 0, false, false.

Give that a try.
AdeH


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
September 27, 2011, 12:39 AM
Aliza Williams
Had your issue been solved Gopal?Just let me know..


Airport parking deals
September 27, 2011, 04:42 PM
Gopal_mys
Hi Adeh,

Thanks for your time.

Even I tried giving the exact file path and this also giving me the same error.

del D:\XX_Gopal\GK\FilesDelete\File3.txt

Service object :-- run variable holds the value del D:\XX_Gopal\GK\FilesDelete\File3.txt.

RunCmdAgent object uses this SREG(run)in runcmd.cmd.label property and all others being default.

This is what the error that I am getting,

error status="1">
   <msg>Exception returned from OS</msg>
   <exception type="java.io.IOException">
      <emsg>Cannot run program "del": CreateProcess error=2, The system cannot find the file specified</emsg>


P-flow is very simple,

I really dont know what is causing this error,is that to do with the access???
or because I am running the p-flow directly from the designer??

As of now I am executing a script directly from a command prompt,as it accepts the wild cards and have made this as a scheduled task.


iWay ISM 5.5/iWay ISM 6.0 on Windows.
September 27, 2011, 11:05 PM
dbeagan
Something like this might do the trick:
 
-SET &APP = 'baseapp';
 APP FI DELPROC DISK delproc.fex
 APP QUERY &APP HOLD
 TABLE FILE FOCAPPQ 
 PRINT COMPUTE APPDEL/A200 = 'APP DELETEFILE &APP "' | GETTOK(FILENAME,70,1,'.',70,'A70') || '" TXT';
 WHERE FILENAME LIKE '%z.txt' 
 ON TABLE SET HOLDLIST PRINTONLY
 ON TABLE HOLD AS DELPROC FORMAT ALPHA 
 END 
-RUN 
-IF &RECORDS EQ 0 THEN GOTO DONE;
 EX DELPROC
-DONE
 

Change the &APP to the one of your choice.
This is not OS specific and avoids explicit looping commands such as -REPEAT.
Use the WHERE statement to select files for deletion.
You can comment out the ON TABLE HOLD line to see the code being generated.
Handle with care, you wouldn't want to accidentally wipe out a bunch of files.


WF 8.2.06
Win10 / IE11
AHTML EXL2K PDF
September 28, 2011, 09:30 AM
Igor Y
Try D:\\XX_Gopal\\GK\\FilesDelete\\File3.txt.


iWay Service Manager (6.0.1 - patch.62627)
DMC Version 7 Release 7
September 29, 2011, 04:29 AM
AdeH
I would raise a case with IBs info response about your initial issue with the file object.

AdeH


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
September 29, 2011, 09:48 AM
AdeH
Hi,
Silly question really, but can you issue the command 'del D:\XX_Gopal\GK\FilesDelete\File3.txt' from your command line? I'm thinking either you're not on windows, so DEL isn't the correct keyword for deleting files, or maybe it's a permissions problem?
Can you try running your pflow from a listener/channel in iSM? I've seen plenty of differences between that and test running in designer in the past...

Ade


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux
September 29, 2011, 02:31 PM
Gopal_mys
Hi Adeh,

Yes, I can able to delete from the command line.

As the designer didn't work out,I am executing a script directly from a command prompt,as it accepts the wild cards and have made this as a scheduled task,that checks and deletes the files everyday.

Previously I was running the p-flow directly from designer,But I have to try the channel option.


iWay ISM 5.5/iWay ISM 6.0 on Windows.
September 29, 2011, 05:50 PM
Waz
Could this be a security issue ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code