AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Folder Contents Script (As in ACDSee)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Calabaza



Joined: 24 Dec 2005
Posts: 9

PostPosted: Sat Jan 14, 2006 6:41 am    Post subject: Folder Contents Script (As in ACDSee) Reply with quote

This script create a list of files contained in a previouly especified directory. It has the same behaviour as the one from acdsee.
I tryed looking if this was already publish, but when i used the search, 22 pages appeared, and i got bored at the second.... so anyway, here's the code:

Code:
FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   MsgBox, You didn't choose a folder.
else
   MsgBox, You have chosen "%OutputVar%".
   Temp = C:\WINDOWS\TEMP
    Loop, %OutputVar%\*.*, 0, 0
    {
        FileAppend, %A_LoopFileName%`n, %Temp%\FolderContents.txt
    }
run, Notepad %Temp%\FolderContents.txt


The file is created in the windows\temp folder (assuming your hard drive is c: ), if not, that's the great thing about this, you can change it according to your needs. For example the save path, or if only lists mp3 or txt files.

Here's something i wanted to do:
I wanted the saved file to be called "name of the folder i choose" - FolderContents.txt

Code:
FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   MsgBox, You didn't choose a folder.
else
   MsgBox, You have chosen "%OutputVar%".
   Temp = C:\WINDOWS\TEMP
    Loop, %OutputVar%\*.*, 0, 0
    {
        FolderName = %A_LoopFileDir%
        FileAppend, %A_LoopFileName%`n, %A_LoopFileDir% - FolderContents.txt
    }
run, Notepad %FolderName% - FolderContents.txt


But it saves the file one folder up, because thats the workin dir, given by %outputvar%.

So whenever i add the path %temp% to the loop, there is a problem with the path. The problems seems to be in the FileAppend function, here's the code: (it does not work) but try it:

Code:
FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   MsgBox, You didn't choose a folder.
else
   MsgBox, You have chosen "%OutputVar%".
   Temp = C:\WINDOWS\TEMP
    Loop, %OutputVar%\*.*, 0, 0
    {
        FolderName = %A_LoopFileDir%
        FileAppend, %A_LoopFileName%`n, %Temp%\%A_LoopFileDir% - FolderContents.txt
    }
run, Notepad %Temp%\%FolderName% - FolderContents.txt


so i need to get the folder name without the path, i havent found it (yet) in the help file. Suggestions???
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Sat Jan 14, 2006 10:47 am    Post subject: Reply with quote

Please try this:
Code:
FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   MsgBox, You didn't choose a folder.
else
  {
    Content =
    Loop, %OutputVar%\*.*, 0, 0
        Content = %Content% %A_LoopFileName%`n

    SplitPath, OutputVar, OutFileName
    Temp = C:\WINDOWS\TEMP\%OutFileName%
    FileAppend, %Content%, %Temp%
    run, Notepad %Temp%
  }
*not tested*
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Calabaza



Joined: 24 Dec 2005
Posts: 9

PostPosted: Sun Jan 15, 2006 8:11 am    Post subject: Reply with quote

I tryed your code toralf but it didn't work, although the code is clear.
But, I was able to solve the problem using the SplitPath function

Code:

FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   MsgBox, You didn't choose a folder.
else
    Temp = C:\WINDOWS\TEMP
    SplitPath, OutputVar, OutFileName
    Loop, %OutputVar%\*.*, 0, 0
    {
        FileAppend, %A_LoopFileName%`n, %Temp%\%OutFileName% - FolderContents.txt
    }
run, Notepad %Temp%\%OutFileName% - FolderContents.txt


Then I'll add the function to erase previous files with the same name.
Thanks for the help...
Back to top
View user's profile Send private message
Calabaza



Joined: 24 Dec 2005
Posts: 9

PostPosted: Wed Mar 01, 2006 5:56 am    Post subject: Reply with quote

This is a new version with the following features:
1. Configuration GUI, preferences saved to ini file.
2. Include folders.
3. Filter file extensions.
4. Change temp dir (where the file is created).

There are two diferent scripts. One for the GUI config and one for the script itself. There are still some thing to do...

Script Code:
Code:

; AutoHotkey Version: 1.x
; Done By Calabaza.
; To do: ShowFileSize, SortByDate, Columns

; Reading configuration data from the ini file
IniRead, IncludeSize, FolderContents.ini, Configuration, IncludeSize, 0
IniRead, IncludeFolders, FolderContents.ini, Configuration, IncludeFolders, 0
IniRead, TempDir, FolderContents.ini, Configuration, TempDir, %TEMP%
IniRead, Extensions, FolderContents.ini, Configuration, Extensions, *.*

; Default values to variables (if no data or ini)
if !TempDir
    TempDir = %TEMP%
if !Extensions
    Extensions = *.*

FileSelectFolder, OutputVar, , 3, Folder Contents - Choose a folder
if OutputVar =
   Return
else
    SplitPath, OutputVar, OutDir
    outFileName = %OutDir% - FolderContents.txt
    FileDelete %TempDir%\%outFileName%
    FileAppend, ,%TempDir%\%outFileName%
    FileList =  ; Initialize to be blank.
    FolderList =  ; Initialize to be blank.
    if IncludeFolders = 1
    {
        Loop, %OutputVar%\%Extensions%, 2, 0
           FolderList = %FolderList%%A_LoopFileName%`n
        Sort, FolderList
        Loop, parse, FolderList, `n
        {
            if A_LoopField =  ; Ignore the blank item at the end of the list.
                continue
            FileAppend, [%A_LoopField%]`n, %TempDir%\%outFileName%
        }
    }
    Loop, %OutputVar%\%Extensions%, 0, 0
       FileList = %FileList%%A_LoopFileName%`n
    Sort, FileList
    Loop, parse, FileList, `n
    {
        if A_LoopField =  ; Ignore the blank item at the end of the list.
            continue
        FileAppend, %A_LoopField%`n, %TempDir%\%outFileName%
    }
    run, Notepad %TempDir%\%outFileName%


GUI Configuration Code
Code:

; Generated by SmartGUI Creater
; FolderContents Config GUI version 0.01

IniRead, IncludeSize, FolderContents.ini, Configuration, IncludeSize, 0
IniRead, IncludeFolders, FolderContents.ini, Configuration, IncludeFolders, 0
IniRead, TempDir, FolderContents.ini, Configuration, TempDir, %TEMP%
IniRead, Extensions, FolderContents.ini, Configuration, Extensions, *.*


if !TempDir
    TempDir = %TEMP%
if !Extensions
    Extensions = *.*


Gui, Add, Text, , Options:
Gui, Add, Checkbox, Checked%IncludeSize% vIncludeSize, Show files sizes
Gui, Add, Checkbox, Checked%IncludeFolders% vIncludeFolders, Show folders
Gui, Add, Text,, Extensions:
Gui, Add, Edit, w120 vExtensions, %Extensions%
Gui, Add, Text,, Temp Dir:
Gui, Add, Edit, w120 r1 vTempDir, %TempDir%
Gui, Add, Button, x140 y127, Choose...
Gui, Add, Button, w60 x10 y160 Default, Ok
Gui, Add, Button, w60 x80 y160, Cancel
Gui, Show, , FolderContents - Options
Return


ButtonChoose...:
    FileSelectFolder, OutputVar, , 3
    if OutputVar =
        Return
    else
        TempDir = %OutputVar%
       GuiControl,, TempDir, %TempDir%
Return


ButtonOk:
Gui, Submit
IniWrite, %IncludeSize%, FolderContents.ini, Configuration, IncludeSize
IniWrite, %IncludeFolders%, FolderContents.ini, Configuration, IncludeFolders
IniWrite, %Extensions%, FolderContents.ini, Configuration, Extensions
IniWrite, %TempDir%, FolderContents.ini, Configuration, TempDir
ExitApp


ButtonCancel:
GuiClose:
ExitApp


I tryed not to put many coments about the code but if someone needs it, I'll post another version with them.
Cheers!


Last edited by Calabaza on Wed Mar 01, 2006 7:17 pm; edited 2 times in total
Back to top
View user's profile Send private message
Me
Guest





PostPosted: Wed Mar 01, 2006 12:28 pm    Post subject: Reply with quote

Reading
Code:
if !TempDir
    TempDir = %A_WinDir%\TEMP

I wondered why you weren't using the (user dependent) system wide %TEMP% variable (c:\Documents and Settings\[username]\Local Settings\Temp on my Win2K machine), but it appears this value is not accessible through AHK? Question
Back to top
evl



Joined: 24 Aug 2005
Posts: 1239

PostPosted: Wed Mar 01, 2006 12:35 pm    Post subject: Reply with quote

TEMP is accessible:
Code:

msgbox, %TEMP%
Back to top
View user's profile Send private message
Calabaza



Joined: 24 Dec 2005
Posts: 9

PostPosted: Wed Mar 01, 2006 6:59 pm    Post subject: Reply with quote

Well, because I didn't know about that variable.
I've fix it now.

Thanks for the tip!!
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Mar 02, 2006 8:34 am    Post subject: Reply with quote

evl wrote:
TEMP is accessible:
Code:

msgbox, %TEMP%

Interesting, I never knew that.

It's a dangerous construction though: when a variable called TEMP is used in the script the '(user dependent) system wide %TEMP% variable' is no longer available.
A built-in 'Operating System and User Info' variable like A_TempDir would be nice.
Back to top
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Mar 02, 2006 10:36 am    Post subject: Reply with quote

No need for a special variable, since it is already in AHK which automatically access environment variables if you try to read an undefined variable.

If you need it, either avoid using this name for a program variable, or save its value before.

Also note that at least in XP, both TMP and TEMP are defined (to same value by default).
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Thu Mar 02, 2006 4:40 pm    Post subject: Reply with quote

There might be an A_TempDir someday because there is a plan to have an option that turn offs the automatic resolution of environment variables. But I'm not sure yet.
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Mar 02, 2006 5:00 pm    Post subject: Reply with quote

I hope, if you provide the option that turn offs the automatic resolution of environment variables, that you will then provide a mean to get them manually on demand...
Something like EnvGet tmpPath, TEMP
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Thu Mar 02, 2006 5:16 pm    Post subject: Reply with quote

Yes, I figured there would have to be a way to get environment variables somehow. The EnvGet syntax you suggested is probably the most consistent with that of EnvSet.
Back to top
View user's profile Send private message Send e-mail
Calabaza



Joined: 24 Dec 2005
Posts: 9

PostPosted: Thu Mar 02, 2006 7:09 pm    Post subject: Reply with quote

How did you know about %TEMP% ?

I looked for it in the help file, but wasnt lucky...
Is there any other variable like that missing in the help?
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Mar 03, 2006 9:06 am    Post subject: Reply with quote

Calabaza wrote:
How did you know about %TEMP% ?

Awh, I was about to indicate how to see that, but I thought: "Naah, everybody knows the trick"...
Plus I have a French system, so I am not sure about English names...

Well, there are two ways:

1) This one works on all Win OSes: Open a command box (Dos/Cmd), type SET{Enter}. It lists all the environment variables. Type set > envList.txt to get them in a text file to study them quietly.
In Win9x systems, these environment variables are set in the C:\autoexec.bat file.

2) On WinNT/2k/XP systems, go to Control Panel > System
You get the System Properties dialog, with lot of tabs. A shortcut to this dialog is WinKey+Pause.
The Advance tab shows buttons, one of them, on the bottom, being "Environment variables" (EnvVars in short). Click on it, you get a new dialog (this is a bit convoluted, don't you think?).
On top, a ListView shows the EnvVars for the current user. I have only these TEMP and TMP ones, pointing inside my Documents and Settings folders.
Below, another ListView shows system EnvVars, which are set for all the users.
Amongst other things, I have the USERNAME, windir, again TEMP and TMP pointing to C:\Windows\Temp (the user settings mask them), PROMPT (I use $p$_$g$s, good for long paths), various PROCESSOR_XXX vars; etc. And some stuff I have put there as an alternative to registry settings, like SciTE_HOME (programs from the Unix world like to search there).

You can create new entries, modify or suppress them.
Note that if you create (or change) an environment variable inside a command box (SET A=XYZ), it will be seen only by programs run from this box.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group