Jump to content

Recommended Posts

Posted

hi,

i may be missing something but can FileFIndFirstfile search subdirectories?. i read through the help file but i didn't find any mention of it.

appreciate your help.

kala

Posted

You might want to try parsing the results of the DOS Dir command, which you can switch to search recursively...

RunWait(@Comspec & " /c Dir C:\Winnt\Temp /s/b > C:\_ParseThis.TXT", "", @SW_HIDE)

Of course, you can also tune it to look for file masks (*.XLS, say), or to discriminate between files and folders. At the DOS prompt say Dir /? for inspiration :whistle:

  • 3 weeks later...
Posted (edited)

Just a follow-up.

Is there a way to pass the result of the dir command directly into a variable or an array instead of into a temporary text file? Like:

$A = RunWait(@Comspec & " /c Dir MyFile.doc /s/b", "", @SW_HIDE)

But that didn't work though. It only passed the exit code of the dos command (0 if not found, 1 if found) :whistle:

Thanks alot.

Edited by kalayaan
Posted

Nope but you can use a combination of exporting the results to a text file and then using the UDF _FileReadToArray() that comes with AutoITV3.

red

Posted (edited)

Easy as cake....

Run(@comspec &" /c dir "& $FOLDER & "\" & $WILDCARDS &" /b/s >"& @TempDir &"\list.tmp")

And parse the file @temp\list.tmp with a FileReadLine loop. :whistle:

EDIT: OPS... I didnt saw that the answer were already there... B)

EZZETABI

:iamstupid:

Edited by ezzetabi
Posted

Not to worry ezzetabi :whistle:

Thanks guys for your kind responses.

I guess, it's either I use a long code (I found some all over the forum) using all AutoIt functions to go into subdirectories or use dos with a temporary text file. I'm thinking that parsing the text file is more simple (is it?) and anyways, I can delete the file afterwards. (I'd appreciate more tips, though)

BTW, what I was trying to do was for the code to look into several directories (some with subdirs) that I use to store my unsorted downloads from the internet and move any file found into another drive at the end of the day.

Thanks a lot.

Posted (edited)

The list into an array can be done in a line or two.

I took a few more to display it out for ya.

I personally like to hide the dos window, and using runwait on the dos box keeps you with the correct data ( AutoIt might process the file before Dos is done making the file.)

I also replace @LF so I have a cleaner array (do to the way I read it in.)

$folder="C:\Documents and Settings\scriptkitty\My Documents"
$wildcards="*.*"
Runwait(@comspec &' /c dir "'& $FOLDER & '\' & $WILDCARDS &'" /b/s >'& @TempDir &'\list.tmp',"",@SW_HIDE)
$lines=StringSplit(Stringreplace(fileread(@TempDir & "\list.tmp",FileGetSize (@TempDir &"\list.tmp")),@lf,""),@CR)

$alllines=""
for $i=1 to $lines[0]-1
$alllines=$alllines& @crlf &"File"&$i & " = "&$lines[$i]
next
msgbox(1,$lines[0],$alllines)

edit.. I would also use ' and add the " so that you can use long filenames in your searches, Dos is kinda perticular sometimes.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Posted (edited)

RunWait is usually better as ScriptKiddy said, but I can give an other advice...

If the operation are long like in big folders you can put a ToolTip... Like

ToolTip("Searching....",@desktopheight /3,0); A often unused part of the screen
RunWait(@comspec &" /c dir "& $FOLDER & "\" & $WILDCARDS &" /b/s >"& @TempDir &"\list.tmp")
ToolTip("")
Edited by ezzetabi

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
  • Recently Browsing   0 members

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