Sign in to follow this  
Followers 0
nazirequbal786

How to pass vriable to cmd while using in autoit

14 posts in this topic

Hi i am newest member of this forum.

i am trying to convert one batch script into autoit. can  anybody suggest how to convert below line.

dir /b n:*%client%>%x%val.txt

 

Share this post


Link to post
Share on other sites



nazirequbal786,

Welcome to the AutoIt forum. :)

Look at _FileListToArray and _FileWriteFromArray in the Help file. Those 2 functions will get you a list of files in a folder which match a particular mask, and then write that list to a file. Come back if you have problems with the code you write. ;)

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

#3 ·  Posted (edited)

$sDir = "yourdir"
$sOutputDir = @DesktopDir
Run( @ComSpec & " /c dir /b c:\*" & $sDir & " > """ & $sOutputDir & "\val.txt""")

or, like melba has shown :)

(use runwait if you are going to interact with the output text) (added wrapping " incase output dir has spaces)

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Thank you both of you to quick reponse.

i am following jdelaney,s suggesion but getting error in @comspec.

dont know why??? do i need to include any specific file.

Share this post


Link to post
Share on other sites

You need to remove the extra "r" from "Run".

Run(@ComSpec & " /c dir /b c:\*" & $sDir & " > """ & $sOutputDir & "\val.txt""")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hey i am not using rRun by the way, still getting error in @compspec.

Share this post


Link to post
Share on other sites

oops, bad edit job on my part...updated above


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Can you please be a bit more specific and describe the error you get? Error message, return code?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

not @compspec...should be @comspec. (this was not a typo in my orig post :) )

If this is not the issue, please post in your script, with it's console output.

or, try this, so you can check your syntax:

$sDir = "yourdir"
$sOutputDir = @DesktopDir
$cmd = @ComSpec & " /c dir /b n:\*" & $sDir & " > """ & $sOutputDir & "\val.txt"""
ConsoleWrite($cmd & @CRLF)
Run($cmd)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Sorry it was typo i am using @comspec only :(

now i am not getting error but not desire output !!

RunWait ( @ComSpec & "/c dir /b E:" & $Client & " >> " & "val.txt")

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

you are missing the "*", if that's needed (in your orig post)...you are also missing the output dir...you would need to first use function

FileChangeDir

to change to where you want the output, or define it like in my sample

example

$sDir = "rs"
$sOutputDir = @DesktopDir
FileChangeDir($sOutputDir)
$cmd = @ComSpec & " /c dir /b c:\*" & $sDir & " > val.txt"
ConsoleWrite($cmd & @CRLF)
Run($cmd)

oh, and you need a space prior to /c

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

it should give me the content of client folder but i am getting nothing

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Yes actually space was problem before /c :)

 Thanks

Edited by nazirequbal786

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

does the dir exist?  you are looking for an exact match of: e:client...where client is your variable

try this, and read the error.txt:

$sDir = "rs"
$sOutputDir = @DesktopDir
FileChangeDir($sOutputDir)
$cmd = @ComSpec & " /c dir /b c:\" & $sDir & " > val.txt 2> error.txt"
ConsoleWrite($cmd & @CRLF)
Run($cmd)



 

edit...just saw your post above, good

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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