Jump to content

Finding jpg files in directories and sub directories


Joboy2k
 Share

Recommended Posts

im having a problem, iv used autoit now for a feew months but for simple task.

but my friend who is a camera technician asked me to make him a program that.

1) Realises he has put in a memory card(could be 4 different types so 4 different drives)

2) Looks in the x:\Dcim\ for the next subfolder("x" being whatever the drive is in use.)

3) finds which subfolder has the Jpg files in

4) opens the Jpg files a slideshow.

can anyone help me?

because iv not even came close to solving how to do it. much appreciated.

Link to comment
Share on other sites

Here is a list of native AutoIt functions you will need and what you will need them for.

DriveGetDrive

- To find a list of drives that are currently inserted. If a new drive is inserted you will find it with this function and you can scan it.

FileFindFirstFile, FileFindNextFile

- To find all subfolders, and then to look for jpg images in those subfolders.

SplashImageOn

- To display the slideshow.

I hope this helps! Your question was very generic so I've tried to give a generic answer.

Link to comment
Share on other sites

better use a 3rd party app like faststoneviewer. or some image viewer which cam be run from the exe (no installation required).

Then just open the image in the imageviewer.

First create an inifinite loop in autoit (while do)

search if the new drives have been plugged in

anytime if a new drive is detected, open it and navigate to the start folder.

create a for loop for as many new drives detected.

using the file functions get a list of all the jpeg files in the folder. put in an array xxx.

get a list of all the folders. put list in yyy array.

create another for loop for the number of folders detected.

browse to 1st folder. get all the jpg files in there and append the path to xxx array.

keep looping till all the jpeg files in the drive have been detected. xxx should contain the paths to all the images.

open each image 1 by 1 using the standalone app (or autoit).

Even better is open drive>>windows search for *.jpg>>open files in standalone. :D

ps. or just ignore the post. :D

i guess your prob is bigger than my power level.

Edited by Rishav
Link to comment
Share on other sites

ok ill try that. but im coming accross another problem.

ill show you what i have so far

$var = drivegetdrive("Removable")

If NOT @error Then

For $i = 1 to $var[0]

$size = DirGetSize($var[$i])

if $size = -1 Then

Else

if fileexists ($var[$i]&"\Dcim\") then

MsgBox(4096,"Drive + Folder" & $i, $var[$i] & " Dcim Exist")

$folder = FileFindFirstFile ($var[$i]&"\Dcim\*")

if $folder = -1 Then

MsgBox(4096,"folder", $var[$i] & " No Folders")

Else

MsgBox(4096,"folder", $var[$i] & " " & $folder)

EndIf

EndIf

endif

Next

EndIf

this is able to notify all removable drivers.

it identifies the drivers with a folder in called DCIM.

BUT

when i try to get the next folder name with

$folder = FileFindFirstFile ($var[$i]&"\Dcim\*")

it keeps coming back with "1"

even though the next folders name is "142Canon"

any ideas y that is?

(the msgboxs wont be need in the future there just there so i know whats going on and whats working)

Edited by joboy2k
Link to comment
Share on other sites

ok ill try that. but im coming accross another problem.

ill show you what i have so far

$var = drivegetdrive("Removable")

If NOT @error Then

For $i = 1 to $var[0]

$size = DirGetSize($var[$i])

if $size = -1 Then

Else

if fileexists ($var[$i]&"\Dcim\") then

MsgBox(4096,"Drive + Folder" & $i, $var[$i] & " Dcim Exist")

$folder = FileFindFirstFile ($var[$i]&"\Dcim\*")

if $folder = -1 Then

MsgBox(4096,"folder", $var[$i] & " No Folders")

Else

MsgBox(4096,"folder", $var[$i] & " " & $folder)

EndIf

EndIf

endif

Next

EndIf

this is able to notify all removable drivers.

it identifies the drivers with a folder in called DCIM.

BUT

when i try to get the next folder name with

$folder = FileFindFirstFile ($var[$i]&"\Dcim\*")

it keeps coming back with "1"

even though the next folders name is "142Canon"

any ideas y that is?

(the msgboxs wont be need in the future there just there so i know whats going on and whats working)

You suppose to use something like this

$var = DriveGetDrive("Removable")
If Not @error Then
    For $i = 1 To $var[0]
        $size = DirGetSize($var[$i])
        If $size = -1 Then
        Else
            If FileExists($var[$i] & "\Dcim\") Then
                MsgBox(4096, "Drive + Folder" & $i, $var[$i] & " Dcim Exist")
                $folder = FileFindFirstFile($var[$i] & "\Dcim\*")
                If $folder = -1 Then
                    MsgBox(4096, "folder", $var[$i] & " No Folders")
                Else
                    While 1
                        $file = FileFindNextFile($folder)
                        If @error Then ExitLoop
                        MsgBox(4096, "folder", $var[$i] & " " & $file)
                    WEnd
                EndIf
            EndIf
        EndIf

    Next
EndIf
Link to comment
Share on other sites

You suppose to use something like this

$var = DriveGetDrive("Removable")
If Not @error Then
    For $i = 1 To $var[0]
        $size = DirGetSize($var[$i])
        If $size = -1 Then
        Else
            If FileExists($var[$i] & "\Dcim\") Then
                MsgBox(4096, "Drive + Folder" & $i, $var[$i] & " Dcim Exist")
                $folder = FileFindFirstFile($var[$i] & "\Dcim\*")
                If $folder = -1 Then
                    MsgBox(4096, "folder", $var[$i] & " No Folders")
                Else
                    While 1
                        $file = FileFindNextFile($folder)
                        If @error Then ExitLoop
                        MsgBox(4096, "folder", $var[$i] & " " & $file)
                    WEnd
                EndIf
            EndIf
        EndIf

    Next
EndIf

this worked great thanks.

But im still making mistakes, and it seems to be the same one.

i now can get the folders name up thanks to wolfworld.

but when i make my search for the file inside that folder it still comes up with a number instead of the files name.

sorry to be a pain xD

iv looked over it a few times and cant see anything different about me looking for the files and looking for folders but the folder search is coming out with names.

if you could help me understand whats is acctually going wrong so i know for the future.

$var = drivegetdrive("Removable")
If NOT @error Then
    For $i = 1 to $var[0]
        $size = DirGetSize($var[$i])
        if $size = -1 Then
        Else
            if fileexists ($var[$i]&"\Dcim\") then
                MsgBox(4096,"Drive + Folder" & $i, $var[$i] & " Dcim Exist")
                $folder = FileFindFirstFile ($var[$i]&"\Dcim\*")
                If $folder = -1 Then
                    MsgBox(4096,"folder", $var[$i] & " No Folders")
                Else
                    While 1
                        $folderdirect = FileFindNextFile($folder)
                        If @error Then ExitLoop
                        MsgBox(4096, "folder", $var[$i] & " " & $folderdirect)
                        ExitLoop
                    WEnd
                    $file = filefindfirstfile($var[$i]&"\Dcim\"&$folderdirect&"\*.jpg")
                    if $file = -1 then
                        MsgBox(4096,"file", $var[$i] & " No Files")
                    Else
                        while 1
                            $filedirect = filefindnextfile($file)
                            If @error Then ExitLoop
                            MsgBox(4096, "file", $var[$i] & " " & $file)
                        WEnd
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
EndIf
Edited by joboy2k
Link to comment
Share on other sites

right 1 update to last post

all i need to find is 1 file name inside the folder.

so lets say the directory line

($var[$i]&"\Dcim\"&$folderdirect&"\*.jpg")

is

(I:\Dcim\142canon\*.jpg")

i only need to find 1 jpg name cause then ill execute this

Run("C:\Windows\system32\cmd.exe","", @SW_MINIMIZE)

WinWait("Administrator: C:\Windows\system32\cmd.exe", "")

controlsend("Administrator: C:\Windows\system32\cmd.exe","","","I:\DCIM\142CANON\*****.JPG") ;****** being the jpg name

Controlsend("Administrator: C:\Windows\system32\cmd.exe","","","{enter}")

controlsend("Administrator: C:\Windows\system32\cmd.exe","","","exit")

Controlsend("Administrator: C:\Windows\system32\cmd.exe","","","{enter}")

winwait ("- Windows Photo Gallery")

winactivate ("- Windows Photo Gallery")

controlclick("- Windows Photo Gallery","","[iD:42000]","") ;this activates slideshow so will automatically go through all photos.

Exit

so can anyone help me by looking at the previous post at why i cant get that 1 file name.

Link to comment
Share on other sites

$var = DriveGetDrive("Removable")
If Not @error Then
    For $i = 1 To $var[0]
        $size = DirGetSize($var[$i])
        If $size = -1 Then
        Else
            If FileExists($var[$i] & "\Dcim\") Then
                MsgBox(4096, "Drive + Folder" & $i, $var[$i] & " Dcim Exist")
                $folder = FileFindFirstFile($var[$i] & "\Dcim\*")
                If $folder = -1 Then
                    MsgBox(4096, "folder", $var[$i] & " No Folders")
                Else
                    While 1
                        $folderdirect = FileFindNextFile($folder)
                        If @error Then ExitLoop
                        $file = FileFindFirstFile($var[$i] & "\Dcim\" & $folderdirect & "\*.jpg")
                        If $file = -1 Then
                            MsgBox(4096, "file", $var[$i] & " No Files")
                        Else
                            While 1
                                $filedirect1 = FileFindNextFile($file)
                                If @error Then ExitLoop
                                MsgBox(4096, "file", $var[$i] & " " & $filedirect1)
                                ExitLoop
                            WEnd
                        EndIf
                    WEnd
                EndIf
            EndIf
        EndIf
    Next
EndIf

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...