Versio 8 not working. Help!!

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

Post Reply
harix
Newbie
Posts: 4
Joined: Thu Jan 18, 2007 3:40 pm

Versio 8 not working. Help!!

Post by harix » Fri Nov 08, 2013 4:17 pm

MJTnet's help desk was gracious enough to try to help me through an emergency even though we were too lazy and cheap to upgrade to a supported version. Since the desk does not even have a copy of so old a version I am turning to this forum. My code is getting the message that the source directory is empty when there are files in the folder. Any suggestions :shock: :shock:

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
// Created by Harry Felker 11/04/13

let>RP_WINDOWMODE=2
Run>C:\WINDOWS\system32\notepad.exe
WaitWindowOpen>Untitled - Notepad

// Read the list from specific path
Let>source_dir=L:\BSL Data Research\NEO_Files\list
Let>archive_dir=L:\BSL Data Research\NEO_Files\archive

GetFileList>%source_dir%*.*,files
Separate>files,;,file_names

//Loop to read through the array
if>%filenames_count%>0
Let>k=0
Repeat>k
Let>k=k+1
//Will Switch the Got Focus later=SetFocus>Mediware 10g
SetFocus>Untitled - Notepad
ReadFile>file_names%k%,current_file
Send>%current_file%%CRLF%

//move the file.
StringReplace>filenames%k%,%source_dir%,%archive_dir%,movepath

//then put the name and path back together, using the new path
Movefile>filenames%k%,%movepath%

Until>k,file_names_count
else
mdl>%source_dir% is empty.
endif

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Fri Nov 08, 2013 5:04 pm

In the separate> line the result will go into the variable file_names, whereas in the subsequent loop you check for the number of items of filenames (filenames_count), ie inconsistent naming of the variable.

harix
Newbie
Posts: 4
Joined: Thu Jan 18, 2007 3:40 pm

Post by harix » Fri Nov 08, 2013 10:32 pm

Thanks, it now reads most of the files but it will not read when only a single file is present in the folder. And, omits one file when 2 or more are present (reads ascending alpha leaving last file unread but does archive all). Thanks for the catch so far. Almost there!!


Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
// Created by Harry Felker 11/04/13

let>RP_WINDOWMODE=2
Run>C:\WINDOWS\system32\notepad.exe
WaitWindowOpen>Untitled - Notepad

// Read the list from specific path
Let>source_dir=L:\BSL Data Research\NEO_Files\list
Let>archive_dir=L:\BSL Data Research\NEO_Files\archive

//Let>source_dir=%userdocuments_dir%\MJT Projects\readfile
//Let>archive_dir=%userdocuments_dir%\MJT Projects\writefile


GetFileList>%source_dir%\*.*,files
Separate>files,;,file_names

//Loop to read through the array
if>%file_names_count%>0
Let>k=0
Repeat>k
  Let>k=k+1
  //Will Switch the Got Focus later=SetFocus>Mediware 10g
  SetFocus>Untitled - Notepad
  ReadFile>file_names_%k%,current_file
  send>%current_file%%CR%

//move the file.
StringReplace>file_names_%k%,%source_dir%,%archive_dir%,movepath

//then put the name and path back together, using the new path
Movefile>file_names_%k%,%movepath%


  Until>k,file_names_count
  else
  mdl>%source_dir% is empty.
  endif


User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1352
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Sat Nov 09, 2013 11:37 pm

hagchr wrote:In the separate> line the result will go into the variable file_names, whereas in the subsequent loop you check for the number of items of filenames (filenames_count), ie inconsistent naming of the variable.
That's not quite right.

Code: Select all

GetFileList>%source_dir%\*.*,files
This will create a list of all the files in the folder, and create it as the variable files. In this case, my files are 1.txt, 2.txt, and 3.txt.

So the result (using a different path, on my PC) is that files is :

C:\Users\DORIAN\Documents\MJT Projects\readfile\3.txt;C:\Users\DORIAN\Documents\MJT Projects\readfile\2.txt;C:\Users\DORIAN\Documents\MJT Projects\readfile\1.txt

Code: Select all

Separate>files,;,file_names
The line above then takes our big long string and splits it into separate variables file_names_1, file_names_2, and file_names_3, using ; as the delimiter.

This is represented in our loop as file_names_%k%.

Separate also creates filenames_count, which represents the number of variables (files) it found - in this case, 3.

Code: Select all

if>%filenames_count%>0
The line above simple asks if the number of files it found was more than zero.

One important thing to note about the original code, is that our ticketing system removed the \ from :

Code: Select all

GetFileList>%source_dir%\*.*,files
...which is why it wouldn't find files.

So that particular issue is resolved, but hagchr still may have some others.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1352
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Sun Nov 10, 2013 12:05 am

So to summarize, here is a generic version.

Code: Select all

let>filepath=%script_dir%

GetFileList>%filepath%\*.*,files
Separate>files,;,file_names
mdl>There are %file_names_count% files in the folder %filepath%

//Loop to read through the array
if>%file_names_count%>0
Let>k=0
Repeat>k
  Let>k=k+1
  message>file_names_%k%
  wait>0.02
  Until>k,file_names_count
  else
  mdl>%filepath% is empty.
  endif
Yes, we have a Custom Scripting Service. Message me or go here

harix
Newbie
Posts: 4
Joined: Thu Jan 18, 2007 3:40 pm

Where I am going wrong.

Post by harix » Mon Nov 11, 2013 3:27 pm

I do not see where I am going wrong. Everything works fine except the code does not read a single file or the last (the file at the end as if the files are sorted alpha/numeric) when 2 or more files are present.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Nov 18, 2013 4:10 pm

Make a macro that does only this:

Let>source_dir=L:\BSL Data Research\NEO_Files\list\
GetFileList>%source_dir%*.*,files
MessageModal>files

Then do this:

1. Go to Windows Explorer and PASTE this in to the address bar:

L:\BSL Data Research\NEO_Files\list\

Take a screen shot, share it here.

2. Run the above script. Copy the contents of the message box that pops up and paste here.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts