[HowTo] get a list of files into a Notepad window

Asked by Florent

Hi,
i have a folder with about ~700 different files,
i would like to copy full file name (with extension) and past it into Notepad,
How to switch between my folder window and notepad (i saw appSwitch()? but it's not working for windows window.. (sorry for my bad english.. i'm french >.<)
And how to do this =/
Thanks in advance !
Regards

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Sikuli motivates you to think in pictures and click's ;-)
... but in many cases solutions like this are much easier:

Since we can do things that are possible with Python, why not do it?

import os
dir = r"full-path-of-your-directory"
outName = dir+r"\dirlist.txt" # will contain the list of your filenames
files = os.listdir(dir) # read the filenames
out = file(outName, "w") # open outputfile
for f in files:
    # here you can inspect each filename
    out.write(f+"\n") # write each filename to one line
out.close()
type("r", KEY_WIN); wait(2) # Run dialog
paste(outName) # enter filename
type(Key.ENTER) # opens file in Notepad
switchApp("dirlist.txt") # brings Notepad window to front

Revision history for this message
Calle Rundgren (c-rundgren) said :
#2

There is a very easy way performing this task using just some ordinary cmd commands:

1. Navigate to the folder

cd c:\Documents and Settings

2. Then type this command

DIR /B /O:N > filename.txt

This will save all the filenames with extensions to a .txt called filename.txt in the same folder as rest of the files.

Sorry for not using sikuli or python, but i think this is the easiest way.

Revision history for this message
Florent (floflo) said :
#3

@RaiMan : Thank you very much !!
I edited a bit the out.write part, and this is working perfectly !! =D

@Calle Rundgren : yeah, thanks for the tip !

Revision history for this message
Florent (floflo) said :
#4

Thanks RaiMan, that solved my question.