Loop through folder and save as Txt (1 Viewer)

prasadgov

Member
Local time
Today, 09:18
Joined
Oct 12, 2021
Messages
50
Hi,

I receive data in files with FTPRCV types dumped into my folder
I need to loop through the folder and save these files as txt files

I receive files as RR20240628060101, RR20240628060102.....
Also, if file types are 20240628060101.FTPRCV, 20240628060102.FTPRCV........then how would the code look like

My code is unfinished
Code:
Dim strfile as string
strfile = Dir("C:\dailyfolder\*RR2024*")
Do While Len(strfile) > 0
.........
How to save all these files as text file with the same names?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:18
Joined
May 21, 2018
Messages
8,748
How to save all these files as text file with the same names?
What does that mean. You cannot same multiple files in the same folder with the same name. These files are already save in your folder. I assume you mean change the extension to .txt not convert to a text file from something else? Are you moving these files, renaming, copying, or what?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:18
Joined
Sep 21, 2011
Messages
14,718
Just append .txt to the name, or replace ftprcv with txt?
Why do you need to change the extension?
 

DickyP

Member
Local time
Today, 14:18
Joined
Apr 2, 2024
Messages
128
The simplest solution is to use Scripting.FileSystemObject. When I can get near myPC I'll knock up some example code. Where do want to save the text files to? The same folder? Are the FTPRCV files the only ones in the folder?

You may well get other solutions before I can produce the promised code, however.
 

prasadgov

Member
Local time
Today, 09:18
Joined
Oct 12, 2021
Messages
50
Just append .txt to the name, or replace ftprcv with txt?
Why do you need to change the extension?
I need to read these contents into a single field in my Access table after which I parse using Mid function.
I will be using either the transfertext or VBA code to get the data into Access.
Under current FTPRCV or RR, I am unable to or I am unaware how to.
I think replacing the file extension as .txt would be the way.
 

prasadgov

Member
Local time
Today, 09:18
Joined
Oct 12, 2021
Messages
50
What does that mean. You cannot same multiple files in the same folder with the same name. These files are already save in your folder. I assume you mean change the extension to .txt not convert to a text file from something else? Are you moving these files, renaming, copying, or what?
Yes, I mean change the extension to .txt
 

prasadgov

Member
Local time
Today, 09:18
Joined
Oct 12, 2021
Messages
50
The simplest solution is to use Scripting.FileSystemObject. When I can get near myPC I'll knock up some example code. Where do want to save the text files to? The same folder? Are the FTPRCV files the only ones in the folder?

You may well get other solutions before I can produce the promised code, however.
I need to read these contents into a single field in my Access table after which I parse using Mid function.
I need to rename them as .txt files either in the same folder or different.
I will be using either the transfertext or VBA code to get the data into Access.
I wonder if the text files can be saved without delimiters?
 

DickyP

Member
Local time
Today, 14:18
Joined
Apr 2, 2024
Messages
128
I need to read these contents into a single field in my Access table after which I parse using Mid function.
I will be using either the transfertext or VBA code to get the data into Access.
Under current FTPRCV or RR, I am unable to or I am unaware how to.
I think replacing the file extension as .txt would be the way.
TransferText doesn't care what extension a file has, as long as it is a text file. Just use files as supplied. Or use FSO as I recommended above and copy the contents directly into
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:18
Joined
Sep 21, 2011
Messages
14,718
I need to read these contents into a single field in my Access table after which I parse using Mid function.
I will be using either the transfertext or VBA code to get the data into Access.
Under current FTPRCV or RR, I am unable to or I am unaware how to.
I think replacing the file extension as .txt would be the way.
Well I have never used transfer text, but I cannot believe it would be bothered about the extension?
 

ebs17

Well-known member
Local time
Today, 15:18
Joined
Feb 7, 2020
Messages
2,064
To analyze a string, you don't have to import it into a field in an Access table first. With a function like the one linked below, you can read the contents of any file, preferably a text file, into a string variable and then immediately start your analysis and processing.
The corresponding results can then be saved for a later point.

ReadFile
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:18
Joined
Feb 28, 2001
Messages
27,646
If you are only renaming a file,


The Name x As y statement should do what you want. As to the other issues, you have been given a good bit of advice so I won't add on.
 

Users who are viewing this thread

Top Bottom