How to read .xls or .csv file from shared drive location

Please provide and example to read an excel file from share drive location.

Hi @pravind, you can do it using excel and read file actions.

If you work with a shared location, you need to write the whole path to the file:
\\server-name\share-name\directory\filename

Hi @ashapkina ,

Shared drive is located on windows server, can we directly access file from shared drive on control tower using file path ?

I had used following code, but it resulted into error:

<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config"scriptlang="groovy">

			<var-def name="file_bytes">
				<script return="bytes_file"><![CDATA[
					import java.nio.file.Files;
					import java.nio.file.Paths;
					import java.util.Arrays;

					File f = new File("\\\\abc.com\\sharedata\\processfiles\\testfile.txt");
					log.warn(f.toString());

					path = "\\\\abc.com\\sharedata\\processfiles\\testfile.txt";
					try {
						p1 = Paths.get(path);
						log.warn("ABS Path:: "+p1.getAbsolutePath());
						bytes_file = Files.readAllBytes(Paths.get(path));
						log.warn(Arrays.toString(bytes_file));
						sys.defineVariable("bytes_file", bytes_file.toString());
					} catch (IOException e) {
						log.warn("Exception Occurred:: "+e);
					}
				]]></script>
			</var-def>

		     <var-def name="s3_link">
				<s3 bucket="temp-files">
					<s3-put path="dummy.txt" acl="PublicRead" content-disposition="inline">
						<var name="file_bytes" />
					</s3-put>
				</s3>
			</var-def>-->

			<!--<log level="WARN" message="s3_link:: ${s3_link}" />-->

	<export include-original-data="true"></export>

</config>

Can you please guide to resolve this issue?
Business requirement is to connect to shared drive pick files and perform various action and store resultant output file back on shared drive.
Format of files will be .csv, .txt, .xls, .xlsx

Looking forward for your response

Regards,
Jeetan

Hi @jeetanlotwani what error did you get?

Hi @ashapkina,

First tried with previously shared code. I got error ‘No such file’ exception even though file was present. Later I tried, below shared code to get file names in the drive. In response, I got null whereas there are various files and folders present in the drive.

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
  
    <script><![CDATA[
      import java.nio.file.*;
   
       filesList = new LinkedList();

       File path = new File("\\\\abc.com\\sharedata\\processfiles");
       File[] listFiles = path.listFiles();
       log.warn("File List::  :: "+listFiles);
       for(File f1 : listFiles){
          if(f1.getName().startsWith("REVERSAL")){
          	filesList.add(f1.getName().toString());
          }
       }
       log.warn("File Name:: "+filesList);
     ]]></script>
			
	<export include-original-data="true"></export>

</config>

Hi @ashapkina,

Looking forward for your response

Regards,
Jeetan H. Lotwani

Are you sure the path to the drive is correct?

Also, do you execute this task from WorkFusion Studio?

Hi @ashapkina

Path mentioned in above shared code is dummy path, as actual path is confidential from client side. However the format is same of actual path as shared in dummy path.
Yes I have tried the code in WorkFusion Studio. It extracts all file names while executing code from studio.

Regards,
Jeetan H. Lotwani

So it works when you play it from WorkFusion Studio and fails when you play it from Control Tower, correct?

Hi @ashapkina,

Yes, It gets executed from studio and i am able to fetch all file names present in the drive.
However from control tower it fails.

Regards,
Jeetan H. Lotwani

The server bots work under local users, and it looks like they don’t have access to this shared drive. Please contact the IT team about this issue.

Hi @ashapkina,

Are you suggesting we will require port opening to access this shared drive from WorkFusion control tower ?

Also can you share steps to check if the drive is accessible or not from control tower server?

Regards,
Jeetan H Lotwani

1 Like

@jeetanlotwani please contact SPA support team (I think you should have access to this portal https://jira.workfusion.com/servicedesk/customer/portals ) - they will provide you with the steps for the solution or will direct to the support specialist that will.

Hi @ashapkina,

Thanks for your support.

Regards,
Jeetan H. Lotwani

1 Like

Hi @ashapkina,

Need some guidance on mapping network drive to Windows RPA server using code.
Shared below is the code and Error. Actual share drive path and credentials are changed for confidential purposes.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<robotics-flow>
	<robot driver="universal">
		<var-def name="file_bytes">

			<script><![CDATA[
				import java.nio.file.*;
	
				String connectCommand = "net use Z: \\\\hostname.abc.com\\RPA-WF\$ /USER:username password";
				log.warn("connectCommand:: "+connectCommand);
				pr = Runtime.getRuntime().exec(connectCommand).waitFor();
	
				System.out.println("Connecting to the shared drive:: "+pr.toString());
	
				File path = new File("Z:");
				File[] listFiles = path.listFiles();
				log.warn("File Name:: "+listFiles.toString());
				sleep(5000);
	
				String disconnectCommand = "net use Z: /delete ";
				prdc = Runtime.getRuntime().exec(disconnectCommand).waitFor();
	
				System.out.println("Disconnecting the shared drive:: "+prdc.toString());
			]]></script>
		</var-def>
	</robot>
</robotics-flow>

<export include-original-data="true"></export>

Error:

org.webharvest.exception.PluginException: [urn:uuid:12314EA77C252166FA15682060467084] robotics-flow executePlugin exception: [nodeId=ce3a7839fe61be71cc14e9ee299b2849http://127.0.0.1:5000] org.webharvest.exception.ScriptException: Config line 10: script block java.io.IOException: Cannot run program "net": error=2, No such file or directory at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RoboticsFlowPlugin.executePlugin(RoboticsFlowPlugin.java:121) at org.webharvest.runtime.processors.WebHarvestPlugin.execute(WebHarvestPlugin.java:125) at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127) at org.webharvest.runtime.Scraper.execute(Scraper.java:169) at org.webharvest.runtime.Scraper.execute(Scraper.java:182) at com.freedomoss.crowdcontrol.webharvest.executor.LocalWebharvestTaskExecutor.executeWebHarvestTask(LocalWebharvestTaskExecutor.java:173) at com.freedomoss.crowdcontrol.webharvest.executor.LocalWebharvestTaskExecutor.executeWebHarvestTask(LocalWebharvestTaskExecutor.java:116) at com.workfusion.service.machine.BotRecordExecutionService.process(BotRecordExecutionService.java:171) at com.workfusion.service.machine.BotRecordExecutionService.process(BotRecordExecutionService.java:142) at com.workfusion.service.machine.BotRecordExecutionService.lambda$processSubmissionWithAllocationLogger$3(BotRecordExecutionService.java:112) at com.workfusion.utils.thread.ThreadMonitoringUtils.executeWithAllocatedMemoryCallback(ThreadMonitoringUtils.java:17) at com.workfusion.service.machine.BotRecordExecutionService.processSubmissionWithAllocationLogger(BotRecordExecutionService.java:112) at com.workfusion.service.machine.BotRecordExecutionService.lambda$processRecord$0(BotRecordExecutionService.java:95) at com.workfusion.utils.thread.NamedThreadTemplate.executeWithNamedThread(NamedThreadTemplate.java:10) at com.workfusion.service.machine.BotRecordExecutionService.processRecord(BotRecordExecutionService.java:95) at com.workfusion.service.machine.thread.RecordProcessThread.run(RecordProcessThread.java:28) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.webharvest.exception.PluginException: org.webharvest.exception.ScriptException: Config line 10: script block java.io.IOException: Cannot run program "net": error=2, No such file or directory at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RobotPlugin.executePlugin(RobotPlugin.java:185) at org.webharvest.runtime.processors.WebHarvestPlugin.execute(WebHarvestPlugin.java:125) at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127) at org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:27) at org.webharvest.runtime.processors.WebHarvestPlugin.executeBody(WebHarvestPlugin.java:246) at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RoboticsFlowPlugin.executePlugin(RoboticsFlowPlugin.java:110) ... 18 more Caused by: org.webharvest.exception.ScriptException: Config line 10: script block java.io.IOException: Cannot run program "net": error=2, No such file or directory at org.webharvest.runtime.scripting.GroovyScriptEngine.eval(GroovyScriptEngine.java:138) at org.webharvest.runtime.processors.ScriptProcessor.execute(ScriptProcessor.java:74) at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127) at org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:27) at org.webharvest.runtime.processors.VarDefProcessor.execute(VarDefProcessor.java:59) at com.freedomoss.crowdcontrol.webharvest.processors.VarDefProcessorValidated.execute(VarDefProcessorValidated.java:28) at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127) at org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:27) at org.webharvest.runtime.processors.WebHarvestPlugin.executeBody(WebHarvestPlugin.java:246) at com.freedomoss.crowdcontrol.webharvest.plugin.selenium.RobotPlugin.executePlugin(RobotPlugin.java:178) ... 23 more Caused by: java.io.IOException: Cannot run program "net": error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at java.lang.Runtime.exec(Runtime.java:450) at java.lang.Runtime.exec(Runtime.java:347) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:237) at Script1_genScript_14.run(Script1_genScript_14.groovy:18) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:444) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:482) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:453) at org.webharvest.runtime.scripting.GroovyScriptEngine.eval(GroovyScriptEngine.java:136) ... 32 more Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:247) at java.lang.ProcessImpl.start(ProcessImpl.java:134) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 41 more