Jump to content

How To Create A Txt.File And A Folder


Recommended Posts

I want to create a txt.file and a folder so

I was looking in the help file and I found function: _fileCreate

so I tryed:

#include <File.au3>
#include <MsgBoxConstants.au3>

$sfilepath = ("C:\Users\pc\Desktop")
_FileCreate($sfilepath)

I get an error message: error Creating/resetting log.    error.1

but when I look at the example

it doesnt create a file or a txt.file 

#include <File.au3>
#include <MsgBoxConstants.au3>

If Not _FileCreate("error.log") Then
    MsgBox($MB_SYSTEMMODAL, "Error", " Error Creating/Resetting log.      error:" & @error)
EndIf
Link to comment
Share on other sites

If you want to create a folder, you can use DirCreate
For the example in the _FileCreate() help page, it works : the error.log file is created into the helpfile folder under you Autoit directory :

C:Program Files (x86)AutoIt3ExamplesHelpfile

Link to comment
Share on other sites

The first example is trying to create a file called Desktop inside the "C:Userspc" folder, it will not create a folder called Desktop, if you want to create this there you NEED to use #RequireAdmin to do it.. Use DirCreate to create a folder. The second example works for me.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The first example is trying to create a file called Desktop inside the "C:Userspc" folder, it will not create a folder called Desktop, 

but if i try this it doesnt wok either

#include <File.au3>
#include <MsgBoxConstants.au3>

$sfilepath = ("C:\Users\pc\Desktop\folder")
_FileCreate($sfilepath)

I get this message:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3" /UserParams    
+>15:52:04 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00020409  OS:WIN_8/  CPU:X64 OS:X64    Environment(Language:0413)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\joesoef pc\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\joesoef pc\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3
+>15:52:04 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>15:52:04 AutoIt3.exe ended.rc:0
+>15:52:04 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.347

If you want to create a folder, you can use DirCreate

For the example in the _FileCreate() help page,

When I try to run the _fileCreate example  nothing happens:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sFldr1 = "C:\Test1\"
    Local $sFldr2 = "C:\Test1\Folder1\"
    Local $sFldr3 = "C:\Test1\Folder1\Folder2\"

    If DirGetSize($sFldr1) <> -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Directory already exists!")
        Return False
    EndIf

    DirCreate($sFldr3)

    RunWait("explorer /root, C:\Test1\Folder1")
    Local $hWnd = WinGetHandle("[TITLE:Folder1;CLASS:CabinetWClass]")

    MsgBox($MB_SYSTEMMODAL, "", "Explorer is opened with Folder2 displayed.")

    DirRemove($sFldr3, 1)
    MsgBox($MB_SYSTEMMODAL, "", "The sub folder: Folder2 has been deleted.")

    WinClose($hWnd)

    DirRemove($sFldr2) ;clean up test folders
    DirRemove($sFldr1) ;clean up test folders
EndFunc   ;==>Example

And I dont really understand it, I only want to create a folder and a txt file on my desktop 

Link to comment
Share on other sites

  • Developers

Keep it simple:

$sfilepath = ("C:\Users\pc\Desktop\folder")
DirCreate($sfilepath)
FileWrite($sfilepath & "\test.txt","Content")

Jos

Edited by Jos
replaced comma by dot

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

thank you jos, but I dont see a txt file apear I get this message:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3" /UserParams    
+>18:01:21 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00020409  OS:WIN_8/  CPU:X64 OS:X64    Environment(Language:0413)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\joesoef pc\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\joesoef pc\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3
+>18:01:21 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\joesoef pc\Desktop\autoit\programma\createfolder.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>18:01:21 AutoIt3.exe ended.rc:0
+>18:01:21 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.3086
Link to comment
Share on other sites

FileWrite($sfilepath & "test,txt","Content")  should be FileWrite($sfilepath & "test.txt","Content")

edit:  When I run the code that you posted I get a file named "test,txt" in the correct folder.  Is this not what you are getting?

I'm running Win7.

Edited by 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

FileWrite($sfilepath & "test,txt","Content")  should be FileWrite($sfilepath & "test.txt","Content")

edit:  When I run the code that you posted I get a file named "test,txt" in the correct folder.  Is this not what you are getting?

I'm running Win7.

I tried that too but  I got nothing, im running windows 8

Why is the path in the script not the exact path you are using?

sorry I dont know what you mean by that im a little bit confussed by this question,

but I just want a text file appear in the desktop  and i also created a map named: folder where the text file needs to be created but nothing happens

Edited by Arclite86
Link to comment
Share on other sites

  • Developers

Your desktop direcory is: "C:Usersjoesoef pcDesktop" ... correct?

Your script contains: "C:UserspcDesktop"

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

  • Developers

@Jos - You ever see a file name with a comma in it?  Seems really odd...

You are correct ... I missed that focussing on the directory conflict I saw. ;)

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

  • Developers

But how can i create a folder instead of a txt file

I honestly think it is now time for you to start thinking and reading so you understand what we are telling you in stead of asking the same questions.

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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