Sign in to follow this  
Followers 0
NicePerson

Files list

38 posts in this topic

#1 ·  Posted (edited)

I am trying to write all files name in a text file but i don't know what is error in my script.

It writes only one file name but, msgbox shows all file names.

Can someone help me plzzz.

Here is 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

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

    $txt = FileOpen("Files.txt", 10)
    FileWrite($txt, "Files name " & $file)
MsgBox(4096, "", "Files name " & $file)

WEnd

; Close the search handle
FileClose($search)
Edited by RMR

Share this post


Link to post
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

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

    FileWrite($txt, "Files name " & $file)
MsgBox(4096, "", "Files name " & $file)

WEnd

; Close the search handle
FileClose($search)


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$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)

While 1

    $file = FileFindNextFile($search)

    If @error Then ExitLoop



    ;$txt = FileOpen("Files.txt", 10)

    FileWrite($txt, "Files name " & $file & @CRLF)

    ;MsgBox(4096, "", "Files name " & $file)



WEnd



; Close the search handle

FileClose($txt)

FileClose($search)

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

RMR,

Why make life difficult when AutoIt can do it for you in one line? ;)

#include <File.au3>

_FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1)

Just change the paths to your own versions. :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

RMR,

Why make life difficult when AutoIt can do it for you in one line? ;)

#include <File.au3>

_FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1)

Just change the paths to your own versions. :blink:

M23

maybe bc of the missing "No files.."-Messagebox ;-)

A-Jay


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

Share this post


Link to post
Share on other sites

ajag,

It was meant as a joke! :blink:

Although it is still simpler with the MsgBox in:

#include <File.au3>

$aArray = _FileListToArray(@ScriptDir, "*.*", 0)
If @error Then 
    MsgBox(0, "Error", "No files/directories matched the search pattern")
Else
    _FileWriteFromArray(@ScriptDir & "\List.txt", $aArray, 1)
EndIf

[joke]

And still easier than playing around with FileFindFirst/NextFile. ;)

[/joke]

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

[joke]

And still easier than playing around with FileFindFirst/NextFile. :blink:

[/joke]

M23

Yep, and it's true - not a joke! ;)

A-Jay


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

Share this post


Link to post
Share on other sites

RMR,

Why make life difficult when AutoIt can do it for you in one line? ;)

#include <File.au3>

_FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1)

Just change the paths to your own versions. :blink:

M23

Melba23

Thanks a lot.

Share this post


Link to post
Share on other sites

[joke]

And still easier than playing around with FileFindFirst/NextFile. :blink:

[/joke]

M23

If you trust those damn UDFs. I've lost all faith in the whole bunch.

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!"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi guys whats up?

I wanna ask something, lets go on...

I got the file as list but i want to convert that list in one line and after every file name there should be a semicolon ; :blink:

For example i got this list:

File.txt
File.exe
File.jpg

Now i want to convert this as

File.txt;File.exe;File.jpg

How can i do this?

Edited by RMR

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

How can i do this?

What about you try something yourself before posting?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You're gonna have to write your own code to get that particular output. Either that, or you use the current code, then recreate the output text file into the format you want by coding a format converter.

Share this post


Link to post
Share on other sites

Plz don't mind for my questions again and again.

My question is i want to replace the last semicolon ";" with nothing and i also tried it meself but my script replaces all the semicolons with text.

I want to replace only last one...

Please don't mind and help me

I got this:

1.txt;2.exe;3.jpg;

But I Want this:

1.txt;2.exe;3.jpg

Here is my try:

$text = StringReplace("1.txt;2.exe;3.jpg;", ";", ".::Replaced text::.")
$numreplacements = @extended
MsgBox(0, "New string is", $text)
MsgBox(0, "The number of replacements done was", $numreplacements)

Thanks!

Share this post


Link to post
Share on other sites

Read the help file better.

$text = StringReplace("1.txt;2.exe;3.jpg;", ";", "", -1)

Share this post


Link to post
Share on other sites

Thanks

Share this post


Link to post
Share on other sites

also

$text = StringTrimRight($text, 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!"

Share this post


Link to post
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

$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

Share this post


Link to post
Share on other sites

Can someone help me plzzz...

Thanks,

RMR

Share this post


Link to post
Share on other sites

RMR,

You have been here long enough to know that you should not bump your own posts within 24 hrs. :blink:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

OK Melba23 i will never do it again.

Btw why people's accounts get blocked here?

Share this post


Link to post
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
Sign in to follow this  
Followers 0