Remove path from folder list?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Remove path from folder list?

Post by RNIB » Tue Nov 21, 2017 2:30 pm

I'm just trying to get a list of folders put into a text file. This is my code so far:

Code: Select all

Input>folder_result,Please Select The Root Folder,
Let>GFL_TYPE=1
GetFileList>%folder_result%\*.*,folders
Separate>folders,;,folder_names
RunProgram>C:\Windows\System32\notepad.exe
WaitWindowOpen>Untitled - Notepad
Let>k=0
Repeat>k
Let>k=k+1
PutClipBoard>folder_names_%k%
Press>Ctrl
Send>>v
Release>Ctrl
Press>Enter
Until>k=folder_names_count
This works but I get results like:

C:\name of folder 1
c:\name of folder 2

How can I remove the path (when the patch could be different each time) so that only the folder name is displayed like:

name of folder 1
name of folder 2

I guess it means stripping out everything before the last \ (as I could be looking inside a subfolder to begin with) but don't know how to do that.

Also the input command works fine if I select a folder but not if I select a drive. What I mean is, if I click on the browse button in the input window but then select a drive instead of a folder, it won't let me set that as the path as the windows button is Open rather than OK. I know I can just type in c: and that works but is there a way of having it let me select a folder or a drive?

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Remove path from folder list?

Post by RNIB » Wed Nov 22, 2017 11:37 am

Well I realised I was being dumb about the open buttons for folder and files (whilst I'm looking for file names I'm still looking at file names within a folder). I've expanded it so that now it lets you choose whether to get a list of files or folders and if you select files you can either get a list of all files or enter the extension you want.

The only bit I want to fix is to remove the path from the folder/file names that are pasted into notepad.

Code: Select all

Ask>Select Yes for Folders No for Files,strResponse
If>strResponse=YES
GoSub>folder
Else
GoSub>file
Endif
Srt>folder
Let>INPUT_BROWSE=2
Input>folder_result,Please Select The Root Folder,
IF>folder_result=
Exit>0
EndIF
Let>GFL_TYPE=1
GetFileList>%folder_result%\*.*,folders
Separate>folders,;,folder_names
RunProgram>C:\Windows\System32\notepad.exe
WaitWindowOpen>Untitled - Notepad
Let>k=0
Repeat>k
Let>k=k+1
PutClipBoard>folder_names_%k%
Press>Ctrl
Send>>v
Release>Ctrl
Press>Enter
Until>k=folder_names_count
END>folder


srt>file
Let>INPUT_BROWSE=0
Input>FileFormat,Please enter the 3 character file format e.g wav. Enter 0 for all files,0
IF>FileFormat=
Exit>0
EndIF
If>FileFormat=0
GoSub>all_files
Else
Let>INPUT_BROWSE=2
Input>file_result,Please Select The Folder Containing The Files
IF>file_result=
Exit>0
EndIF
GetFileList>%file_result%\*.%FileFormat%,FormatFileList
Separate>FormatFileList,;,file_names
RunProgram>C:\Windows\System32\notepad.exe
WaitWindowOpen>Untitled - Notepad
SetFocus>Untitled - Notepad
Let>k=0
Repeat>k
Let>k=k+1
PutClipBoard>file_names_%k%
Press>Ctrl
Send>>v
Release>Ctrl
Press>Enter
Until>k=file_names_count
endif

Srt>all_files
Let>INPUT_BROWSE=2
Input>file_result,Please Select The Folder Containing The Files
If>file_result=
Exit>0
GetFileList>%file_result%\*.*,files
Separate>files,;,file_names
RunProgram>C:\Windows\System32\notepad.exe
WaitWindowOpen>Untitled - Notepad
Setfocus>Untitled - Notepad
Let>k=0
Repeat>k
Let>k=k+1
PutClipBoard>file_names_%k%
Press>Ctrl
Send>>v
Release>Ctrl
Press>Enter
Until>k=file_names_count
END>all_files

END>file
So lets say I have a folder on the root of the C: drive called My Folder and inside that were 5 txt files called 1,2,3,4,5

At the moment the text pasted into Notepad will be:

C:\My Folder\1.txt
C:\My Folder\2.txt
C:\My Folder\3.txt
C:\My Folder\4.txt
C:\My Folder\5.txt

Instead I just want:
1.txt
2.txt
3.txt
4.txt
5.txt

The same would apply for folders.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Remove path from folder list?

Post by JRL » Wed Nov 22, 2017 1:37 pm

Try ExtractFileName>

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Remove path from folder list?

Post by RNIB » Wed Nov 22, 2017 1:43 pm

Ahh! Cheers JRL, that solved it.

I was looking under File Handling Commands and didn't think to look under String Handling which would have made more sense :oops:

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