Jump to content

Files list


Recommended Posts

$search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$txt = FileOpen("Files.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
$txt2 = FileOpen("Files2.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    FileWrite($txt, $file & ";")
    $read = FileRead($txt)
    $text = StringTrimRight($read, 1)
    FileWrite($txt2, $text)

WEnd

; Close the search handle
FileClose($search)

Not working

Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings.

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

This is written for getting all files name in a text file and each name should be seperated with semicolon.

when i run this it works fine but i don't want semicolon at the last of text file.

So , can you help me please?

i tried to trim last word but that does not work...

$search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$txt = FileOpen("Files.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
$txt2 = FileOpen("Files2.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    FileWrite($txt, $file & ";")
    $read = FileRead($txt)
    $text = StringTrimRight($read, 1)
    FileWrite($txt2, $text)

WEnd
Link to comment
Share on other sites

You need to close the file handles for the written data to be saved.

Also, why write everything to the file directly? Why not just process all the data using strings then just do one FileWrite when all the processing is over with?

Link to comment
Share on other sites

How to do this in my script?

$search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$txt = FileOpen("Files.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
$txt2 = FileOpen("Files2.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    FileWrite($txt, $file & ";")
    $read = FileRead($txt)
    $text = StringTrimRight($read, 1)
    FileWrite($txt2, $text)

WEnd
Link to comment
Share on other sites

  • Moderators

RMR,

why people's accounts get blocked here?

Bumping your own posts too quickly, not making any effort yourself, and using phrases like "write this please..." are a good way to draw the attention and ire of the moderating team, as already shown in this post earlier in this very topic. :P And continuing in your present manner may well mean that you cease to get any help from the regular members, which I am sure you would not want either. ;)

I suggest that you try to make a greater effort to resolve your problems yourself. There is no shame in being a new coder - we all started there at some point - but you need to start trying some things yourself. I borrowed this from Mat's signature, but the sentiment is one I share fully:

Hear and forget. See and remember. Do and understand.

So, try a few things for yourself. have you read and understood the excellent tutorials that you find here and here? If not, please do so - they will help you enormously in understanding how AutoIt code is structured.

We have many members here who have little or no understanding of the code they (with the help of many others) have produced. Remember the old saying:

"Give a man a fish, you feed him for a day; give a man a net and you feed him forever".

We try to be net makers and repairers, not fishmongers. But it is up to you to learn to how to throw your net. We are more than willing to help, but we need to see more effort on your part. :blink:

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

  • Developers

i can't figure it on mine i am a newbie.

write this please...

Let me make it easy for you: You either start putting some effort in it yourself or you will be put on a "posting questions ban" for a while.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hear and forget. See and remember. Do and understand.

"Give a man a fish, you feed him for a day; give a man a net and you feed him forever".

M23

Nice, I like the first one. Here is one

To teach is to learn twice.

@RMR - it looks like you may be trying to bit off a bit to much. Look a Files (reading and writing) in the help file and play round with them then try to introduce more things slowly. This way you will understand what the code is doing and errors will be much more obvious. I also you look up ConsoleWrite as it can be used in your code to help understanding what is going on where - this print out vars.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

What are you trying to do with a FileRead() in that loop? Are you trying to contcatenate files or just create a file list? You don't use FileRead(0 in a list situation.

Btw why people's accounts get blocked here?

For breaking any forum rules but mainly for repeated offences of the following

Posting on topics that are not allowed

Arguing with moderatore

General stupidity.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Fileread does what it says it does, it READS a file so you don't need that and I already gave you the solution for the semi-colon as have others.

$sStr = "text1;text2;text3;text4;text5;"
$sStr = StringTrimRight($sStr, 1)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

GEOSoft,

I followed your method but...

$search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$txt = FileOpen("Files.txt", 10)   ;<<<<<<<<  this must not be within the While-Loop!
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $sStr = $file & ";"
    $sStr = StringTrimRight($sStr, 1)
    FileWrite($txt, $sStr)
WEnd

; Close the search handle
FileClose($search)

Files.txt should be contain:

text1;text2;text3;text4;text5

But it contain:

text1text2text3text4text5

I tried a lot now what is my mistake?

Please don't mind!!1

Edited by RMR
Link to comment
Share on other sites

$search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$sStr = ""
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $sStr &= $file & ";";; You are changing the value of $sStr everytime you do this.  You want to just append the next file and the ;
    ;;$sStr = StringTrimRight($sStr, 1);;  Only after the loop has completed
    ;;FileWrite($txt, $sStr);;  We already told you about NOT putting this in a loop.  FileWriteLine() would be different
WEnd
; Close the search handle
FileClose($search)
If $sStr ;; here we check for a valid string
    ;; If we have a valid string then perform the next operation.
    $txt = FileOpen("Files.txt", 10)
    FileWrite($txt, StringTrimRight($sStr, 1))
    FileClose($txt) ;; Close the handle to the open file
EndIf

Now a bit of checking in the help file and you would have had no difficulty what-so-ever seeing what we pointed out earlier. The help file is the best friend you have around here so you better learn to use it.

Don't just read our replies and guess at how to implement the suggestions, check on the function usage. We don't write people code for them, instead we deal in generalities that will point them in the right direction and that direction will invariably lead to the help file.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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