Jump to content

Special Character help


Recommended Posts

Hi folks. It has been some time since I have used AutoIT so I am a little rusty. I am revisting some code that is basically reading an ini file and creating a CMD on the fly in order to perform some copy operations. The problem I am running into is that one of the lines in my INI file contains a "&" sign. I know how to deal with this in my CMD file that I am creating on the fly I am just having an issue getting AutoIT script to deal with it. Basically what I did was modify the ini so that I preceded the "&" sign with a "^". This tells DOS to escape out the "&" and use it in the string as I intended. The problem is that when my ini read section of the AutoIT script his the "^" symbol it tells me I cant do that without an array. I can post some example code in a bit once I clean it up.

Link to comment
Share on other sites

OK, post your code and we'll see.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

dim $PRJ_Name
dim $PRJ_Number
dim $INI_Read
dim %SRV_Loc

IF $INI_Read = "Name of Office" then
    $INI_Read="Projects.ini"
    $SRV_LOC="[url="file://srvdata"]srvdata[/url]"
    $PRJ_INI=IniReadSection($INI_Read,"Project_List")
    $PRJ_Name = ($PRJ_INI[1][1])
    $PRJno_INI=IniReadSection($INI_Read,$PRJ_Name)
    For $i = 1 To $PRJ_INI[0][0]
     GUICtrlSetData($Project_List,$PRJ_INI[$i][1],$PRJ_INI[1][1]) ; add other item snd set a new default
    Next
   
    For $i = 1 To $PRJno_INI[0][0]
     GUICtrlSetData($ProjectNo_List,$PRJno_INI[$i][1],$PRJno_INI[1][1]) ; add other item snd set a new default
    Next
   EndIf

$PRJ_Number = GUICtrlRead($ProjectNo_List)
   $FileName = "C:tempPojects.bat"
   $file = FileOpen($FileName, 10) ; which is similar to 2 + 8 (erase  + create dir) 
   FileWriteLine($file,"@echo off")
   FileWriteLine($file,"REM Project Setup")
   FileWriteLine($file,"REM ------------------- Script Functions -------------------")
   FileWriteLine($file,"REM PRJ_Name and PRJ_Number and Server_Location are the only values that need updated per Revit project")
   FileWriteLine($file,"REM Creates Local Project Folders")
   FileWriteLine($file,"")
   FileWriteLine($file,"set PRJ_Name=" & $PRJ_Name)
   FileWriteLine($file,"set PRJ_Number=" & $PRJ_Number)
   FileWriteLine($file,"set Server_Location=" & $SRV_LOC)

FileWriteLine($file,"copy ""C:Projects%PRJ_Name%%PRJ_Number%DATAStuff*-Archive.rvt"" ""C:Projects%PRJ_Name%%PRJ_Number%Archives"" /y")

INI is structured as below

[Project_Location]

1=Office 1

2=Office 2

[Project_List]

1=BBS

2=Jeff & John

[bBS]

1=1234

[Jeff & John]

1=1234

Like I tried to explain in my original pose my problem is the Jeff & John string that I turn into a path for a DOS copy. I have to escape out the & sign in DOS using the ^. However when I tried just adding that into the string in the INI file the AU3 script choked on it.

Link to comment
Share on other sites

Why not just use the FileCopy function in AutoIt instead of hacking together a batch file to do it? I think the main problem with your batch file is that you need to use quotes around the pathname if it contains spaces, the "&" probably isn't the problem.

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

I use the create BAT file for other things. It was also a way for me to create a log so to speak to make sure everything was working. A good point and something I may revisit. I have been using this for several years and the qutes and spaces have never been an issue. This just started failing on me when they add a & to the file path.

Link to comment
Share on other sites

  • Moderators

jcampbell,

It all works fine for me: :bye:

Ini:

[Project_Location]
1=Office 1
2=Office 2

[Project_List]
1=BBS
2=Jeff ^& John

[BBS]
1=1234

[Jeff ^& John]
1=1234

Script:

#include <GUIConstantsEx.au3>

Dim $PRJ_Name
Dim $PRJ_Number
Dim $INI_Read
Dim $SRV_Loc
$INI_Read = "Name of Office"

$hGUI = GUICreate("Test", 500, 500)

$Project_List = GUICtrlCreateCombo("", 10, 10, 200, 20)

$ProjectNo_List = GUICtrlCreateCombo("", 10, 50, 200, 20)

$cButton = GUICtrlCreateButton("Test", 10, 100, 80, 30)

GUISetState()

If $INI_Read = "Name of Office" Then
    $INI_Read = "Projects.ini"
    $SRV_Loc = '[url="file://srvdata"]srvdata[/url]'
    $PRJ_INI = IniReadSection($INI_Read, "Project_List")

    $PRJ_Name = ($PRJ_INI[1][1])
    $PRJno_INI = IniReadSection($INI_Read, $PRJ_Name)

    For $i = 1 To $PRJ_INI[0][0]
        GUICtrlSetData($Project_List, $PRJ_INI[$i][1], $PRJ_INI[1][1]) ; add other item snd set a new default
    Next

    For $i = 1 To $PRJno_INI[0][0]
        GUICtrlSetData($ProjectNo_List, $PRJno_INI[$i][1], $PRJno_INI[1][1]) ; add other item snd set a new default
    Next
EndIf


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            Test()
    EndSwitch

WEnd

Func Test()


    $PRJ_Name = GUICtrlRead($Project_List)
    $PRJ_Number = GUICtrlRead($ProjectNo_List)
    $FileName = "Projects.txt"
    $file = FileOpen($FileName, 10) ; which is similar to 2 + 8 (erase  + create dir)
    FileWriteLine($file, "@echo off")
    FileWriteLine($file, "REM Project Setup")
    FileWriteLine($file, "REM ------------------- Script Functions -------------------")
    FileWriteLine($file, "REM PRJ_Name and PRJ_Number and Server_Location are the only values that need updated per Revit project")
    FileWriteLine($file, "REM Creates Local Project Folders")
    FileWriteLine($file, "")
    FileWriteLine($file, "set PRJ_Name=" & $PRJ_Name)
    FileWriteLine($file, "set PRJ_Number=" & $PRJ_Number)
    FileWriteLine($file, "set Server_Location=" & $SRV_Loc)

    FileWriteLine($file, "copy ""C:Projects%PRJ_Name%%PRJ_Number%DATAStuff*-Archive.rvt"" ""C:Projects%PRJ_Name%%PRJ_Number%Archives"" /y")

EndFunc   ;==>Test

Result:

@echo off
REM Project Setup
REM ------------------- Script Functions -------------------
REM PRJ_Name and PRJ_Number and Server_Location are the only values that need updated per Revit project
REM Creates Local Project Folders

set PRJ_Name=Jeff ^& John
set PRJ_Number=1234
set Server_Location=[url="file://srvdata"]srvdata[/url]
copy "C:Projects%PRJ_Name%%PRJ_Number%DATAStuff*-Archive.rvt" "C:Projects%PRJ_Name%%PRJ_Number%Archives" /y

What is different between this code and yours? :oops:

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

If there's truly a valid reason for using environment variables, then the following line won't fly without quoting the variable:

FileWriteLine($file,"set PRJ_Name=" & $PRJ_Name)

Edit: Nevermind, being up til 5am has my brain cell malfunctioning :oops: I will stick with my opinion that avoiding environment variables might be a good idea.

Edited by Spiff59
Link to comment
Share on other sites

  • Moderators

jcampbell,

Seen any differences between our 2 versions of the code yet? :oops:

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