Jump to content

From the Beginning (DIM)


Recommended Posts

This is what I have so far:

Dim $spath="C:\Users\me\Documents\", $sfilter="*", $iflag=2

1. Dimension an array ($fldrs) to 100 elements

Dim $fldrs[100] ??

2. Set variable $fldrs equal to filelist

$fldrs=_FileListToArray($spath,$sfilter,$iflag) ??

3. Print out the folders in the $fldrs array (i now understand what element 0 is for, but the $SPATH does not work; I get a runtime error)

Link to comment
Share on other sites

with what you have - it will return folders names only

also if there are more than 100 folders - it is going to only find the first 100

use Dim $fldrs[ubound($spath)] to get all the folders

EDIT

forgot to say, you will need to use a for loop to go through each of the folder names/paths

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

ok, i understand what you wrote and all i want is the name of the subfolders below c:\users\me\documents\

such as ..autoit, ..pdf, ..wordocs, etc.

I also understand that $fldrs[100] will truncate anything after element 100. i will have to look at ubound.

Are you telling me that all of what I wrote so far is correct?

Is $spath="C:\Users\me\Documents\" a valid statement AND

Can i say $fldrs=filelisttoarry($spath, ....) and have it work cuz it isn't working?

what am i doing wrong?

Link to comment
Share on other sites

hold a second - i need to test it first

try this

#Include <File.au3>
#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf

_ArrayDisplay($FileList,"$FileList")


For $i = 1 To UBound($FileList) - 1
    MsgBox('','Folder number = ' & $i, $FileList[$i])
Next

EDIT your code is not going to work - as this line

Dim $spath="C:\Users\me\Documents\", $sfilter="*", $iflag=2

will not work try

local $spath="C:\Users\me\Documents\"

local $sfilter="*"

local $iflag=2

EDIT again

changed the DIM to Local as it is not an array

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

hold a second - i need to test it first

try this

#Include <File.au3>
#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf

_ArrayDisplay($FileList,"$FileList")


For $i = 1 To UBound($FileList) - 1
    MsgBox('','Folder number = ' & $i, $FileList[$i])
Next

EDIT your code is not going to work - as this line

Dim $spath="C:\Users\me\Documents\", $sfilter="*", $iflag=2

will not work try

local $spath="C:\Users\me\Documents\"

local $sfilter="*"

local $iflag=2

EDIT again

changed the DIM to Local as it is not an array

Link to comment
Share on other sites

now i kinda see. i will try what you wrote.

once this works all i have to do is to erase the contents of the current folder on a flash drive and copy the contents of the corresponding

hard drive folder to the flash drive. this is going to be my lazy man's backup program.

Link to comment
Share on other sites

I would TEST and RETEST - before moving and deleting files

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

This is what I have so far:

Dim $spath="C:\Users\me\Documents\", $sfilter="*", $iflag=2

1. Dimension an array ($fldrs) to 100 elements

Dim $fldrs[100] ??

2. Set variable $fldrs equal to filelist

$fldrs=_FileListToArray($spath,$sfilter,$iflag) ??

3. Print out the folders in the $fldrs array (i now understand what element 0 is for, but the $SPATH does not work; I get a runtime error)

In your original post, there was nothing wrong with your script. The only thing that I would change is there is no need to initialize the array with any amount Your line: "Dim $fldrs[100]" because when you use the _FileListToArray() function it assigns the variable as an array of the proper size. You could have made it

"Dim $fldrs[1]"

and when you run the _FileListToArray() function it will assign the variable as an array to whatever size it returns, as long as the function itself runs without an error. You basically did this in your script:

$Var = 1
$Var = 15
MsgBox(0, '', $Var)
Then value of $Var will be the last thing that is assigned to it.

Par example:

#include <array.au3>
#include <File.au3>
Dim $Spath = @MyDocumentsDir, $Sfilter = "*", $Iflag = 2


Dim $Fldrs

$Fldrs = _FileListToArray($Spath, $Sfilter, $Iflag)
_ArrayDisplay($Fldrs)
Edited by Varian
Link to comment
Share on other sites

In your original post, there was nothing wrong with your script. The only thing that I would change is there is no need to initialize the array with any amount Your line: "Dim $fldrs[100]" because when you use the _FileListToArray() function it assigns the variable as an array of the proper size. You could have made it

"Dim $fldrs[1]"

and when you run the _FileListToArray() function it will assign the variable as an array to whatever size it returns, as long as the function itself runs without an error. You basically did this in your script:

$Var = 1
$Var = 15
MsgBox(0, '', $Var)
Then value of $Var will be the last thing that is assigned to it.

Par example:

#include <array.au3>
#include <File.au3>
Dim $Spath = @MyDocumentsDir, $Sfilter = "*", $Iflag = 2


Dim $Fldrs

$Fldrs = _FileListToArray($Spath, $Sfilter, $Iflag)
_ArrayDisplay($Fldrs)

Link to comment
Share on other sites

good, glad to hear my logic was right somewhat. i will set $fldrs(1) and let the function array it to proper size.

I don't understand the Dim $spath=@mydocumentsdir ...at all... why don't i use the path in Quotes??

here is what i want to do:

dim $fldrs

$Fldrs = _FileListToArray($Spath, $Sfilter, $Iflag)

; prompt for user to put usb drive in

; find the drive letter for that drive

; erase all files and folders on that drive

; go through each folder in C:mydocuments (Via the $fldrs array) and (for/next loop)

copy each folder from C: to the usb drive

; next

; set a var for the path to Favorites

filelisttoarry all files and folders here (both exist in Favorites)

do the same thing with favorites subdirectory that i did above (for/next)

End Script

Link to comment
Share on other sites

pullmyefinger,

It does not look like _filelisttoarray will recurse sub-folders. If you are using this for portability or backup then you may want to consider VERY carefully what you are doing.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

pullmyefinger,

It does not look like _filelisttoarray will recurse sub-folders

Indeed it does not. :x

But the RecFileListToArray UDF in my sig does work in subfolders - and has a few other improvements as well! :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...