How to find the name of a file in a folder

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Trevor Hughes
Junior Coder
Posts: 25
Joined: Sun Dec 15, 2013 9:27 pm

How to find the name of a file in a folder

Post by Trevor Hughes » Wed Jan 23, 2019 6:43 pm

Hello

I am currently using the following to get a list of files in a folder to use in my script:

GetFileList>c:\Temp\*.*,files
Separate>files,;,file_names
ArraySort>file_names

This works well in giving me the full path to the file. However I want to use a variable to store just the filename (without the path),

Could anyone help with this.

Kind regards
Trevor

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to find the name of a file in a folder

Post by Grovkillen » Wed Jan 23, 2019 7:43 pm

Let>ME=%Script%

Running: 15.0.27
version history

Neib74656
Junior Coder
Posts: 29
Joined: Fri Sep 10, 2021 10:51 pm

Re: How to find the name of a file in a folder

Post by Neib74656 » Thu Jan 12, 2023 7:06 pm

Hello Everyone,

This seems to work for what I need but only on a single file.

I need to extract the file names to rows in Excel. Is it possible to do this without looping extract file name?

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

Re: How to find the name of a file in a folder

Post by Dorian (MJT support) » Thu Jan 12, 2023 7:21 pm

I hope I'm understanding correctly, but if you're using GetFileList and then looping through the results extracting the file names, ExtractFileName would need to be inside the loop :

Code: Select all

Let>GFL_SORTTYPE=3
GetFileList>d:\compiled\*.*,files
Separate>files,;,file_names
 
Let>k=0
Repeat>k
  Let>k=k+1
  ExtractFileName>file_names_%k%,ThisFN
  mdl>ThisFN
Until>k,file_names_count
Then of course the code that writes to Excel would also be in that loop.
Yes, we have a Custom Scripting Service. Message me or go here

Neib74656
Junior Coder
Posts: 29
Joined: Fri Sep 10, 2021 10:51 pm

Re: How to find the name of a file in a folder

Post by Neib74656 » Fri Jan 13, 2023 10:04 pm

Thanks Dorian!

I was hoping to avoid doing it with a loop but I guess it is the only option.

Thank you as always!

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