Help with IfFileExists

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

Help with IfFileExists

Post by Aaron » Wed May 23, 2007 7:31 am

OK

I need help with a script that will write a file when a new file exists within the directory:

Code: Select all

C:\Documents and Settings\Owner\My Documents\Outlook backup Files\*.txt
As you can see, I dont know what the name is as it wiil be named by the subject of the email

I know I could just copy the file, but the next part of the script will keep the file and write to it in the future using the name wich is a variable. I have the rest of the script and it works just fine, I just need help with this part.

Here's where the problem Starts:

Code: Select all

IfFileExists>C:\Documents and Settings\Owner\My Documents\Outlook backup Files\*.txt
The problem arizes in the next few lines, as follows:

Code: Select all

Let>k=1
Label>START

ReadLn>C:\Documents and Settings\Owner\My Documents\Outlook backup Files\*.txt,k,line

If>line=##EOF##,finish

WriteLn>C:\Documents and Settings\Owner\My Documents\Outlook backup Files\BackUps\%TheNameOfTheFile%.txt,result,%line%

Let>k=k+1

Goto>START

Label>finish

I need help finding a way to get the file name when it is a wild card.
Any thoughts would be helpful

Thanks
Aaron

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

Post by Marcus Tettmar » Wed May 23, 2007 8:08 am

Use GetFileList. Also I wonder why you are reading all lines from one file and writing them to another. You'll just end up with a copy of the file. So why not just use CopyFile?

Code: Select all

GetFileList>C:\Documents and Settings\Owner\My Documents\Outlook backup Files\*.txt,files
Separate>files,;,file_list
If>file_list_count>0
   Let>k=1
   Repeat>k
      Let>ThisFile=file_list_%k%
      StringReplace>ThisFile,C:\Documents and Settings\Owner\My Documents\Outlook backup Files\,C:\Documents and Settings\Owner\My Documents\Outlook backup Files\BackUps\,NewFile
      CopyFile>ThisFile,NewFile
      Let>k=k+1
   Until>k>file_list_count
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

I know I could just copy the file, but the next part of the

Post by Aaron » Thu May 24, 2007 4:29 am

Hi Marcus

Please read the post again. It says:
I know I could just copy the file, but the next part of the script will keep the file and write to it in the future using the name which is a variable.

Ive been working all day on the script, heres what I got:

Code: Select all


GetFileList>C:\Documents and Settings\Owner\My Documents\Outlook backup Files\*.txt,files
Separate>files,;,file_names
   Let>k=1
   Repeat>k
      StringReplace>file_names_%k%,C:\Documents and Settings\Owner\My Documents\Outlook backup Files\,,file_name

// I NEED TO SAVE ,r,file_name AND USE IT IN THE FILE NAME PART BELOW %file_name%

   Let>k=k+1
   Until>k,file_names_count

// THIS PART BELOW WOULD WRITE A COMMENT AT THE TOP OF THE NEW TEXT

Let>WriteFromFile=C:\Documents and Settings\Owner\My Documents\Outlook backup Files\%file_name%
Let>WriteToFile=C:\Documents and Settings\Owner\My Documents\Outlook backup Files\BackUps\%file_name%



Day>the_day

Month>the_month

Year>the_year

GetTime>time

Let>Comment=//

Let>msg=%Comment% The Email Named: %WriteFromFile% was Updated on %the_month%/%the_day%/%the_year% at %time%


WriteLn>%WriteToFile%,result,%msg%





// THIS IS WHERE I THINK THE PART I NEED HELP WITH WOULD GO !!!





// THIS PART BELOW WOULD WRITE TO THE TEXT 

Let>L=0

Label>Write_To_Email

ReadLn>%WriteFromFile%,L,line

If>line=##EOF##,finish

WriteLn>%WriteToFile%,result,%line%

Let>L=L+1

Goto>Write_To_Email

Label>finish


WriteLn>%WriteToFile%,result,
WriteLn>%WriteToFile%,result,
WriteLn>%WriteToFile%,result,=========================================================================
WriteLn>%WriteToFile%,result,                             New Email Below
WriteLn>%WriteToFile%,result,=========================================================================



// I WOULD THEN WANT TO DELETE THE FILE I WROTE FROM SO AS NOT TO WRITE IT AGAIN.


I dont need to write the names, I need them to find the file name and then save it as a var and use it in the script.

Hopefuly this makes sence, I suck at explanations

The rest of the script is out of place but thought it would help to see the rest of the code and what im doing.

Also, back to my original post.
I would need ifFileExiste to be running always to grab the new file, write to the text file in the backups folder and then delete the original text filein the Outlook backup Files.


ifFileExist
start the macro above

Thanks
Aaron

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

read from a wildcard,

Post by Aaron » Sun Jun 10, 2007 3:10 pm

You said
Earlier you were trying to read from a wildcard, which can't be done (as I'm sure you learned)...

Sure you can read from a wildcard, I have never had a problem with that.

Anyways thanks for your response.

I have the script working now.
Aaron

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