emendelson Posted April 26, 2023 Posted April 26, 2023 I've created a few compiled scripts that let the user drop one or more files on the script so the script can process the file. This works perfectly if the pathname of the file has no spaces in it. The script parses the command line, and each parameter is a file. But when a dropped file has a space in its name, the command line sees it as two parameters, not one, and can't process the file. I've been trying to think of a solution to this, and one idea is this: If the command-line parameter has no extension, then store it (followed by a space( in a variable; if the next parameter has an extension, then append the next parameter to the first parameter to create a filename and test whether the file exists. This shouldn't be hard to do, but if someone has already written a routine to do this, I would be grateful to have it, so that I don't have to reinvent the wheel. Thanks for any help.
Guest Posted April 26, 2023 Posted April 26, 2023 (edited) 3 hours ago, emendelson said: But when a dropped file has a space in its name, the command line sees it as two parameters, not one, and can't process the file. Just in case you missed this issue : If you pass a command line parameter to a script (e.g. strings, here pathnames) which contain spaces, then the parameter must be enclosed in quotes. Wrong : MyExe.exe c:\test\myfile 1.txt c:\test\myfile 2.txt c:\test\myfile 3.txt Correct : MyExe.exe "c:\test\myfile 1.txt" "c:\test\myfile 2.txt" "c:\test\myfile 3.txt" Edited April 26, 2023 by Musashi
ioa747 Posted April 26, 2023 Posted April 26, 2023 here is an example, excerpt from the 209863-copy-move-folders-or-files-according-to-its-extension, where you can throw a file or several files, in the executable exe, or in the shortcut, even if it was not compiled into an executable exe expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ;------------------------------------------------------------------------------ ; Title...........: CmdLineTester.au3 ; Description.....: Test CmdLine Parameters ;------------------------------------------------------------------------------ #include <TrayConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <EditConstants.au3> #include <File.au3> #Region (=== GUI ===) Global $hGUI = GUICreate("$CmdLine", 400, 151, 17, 552, -1, BitOR($WS_EX_TOPMOST, $WS_EX_NOACTIVATE)) GUISetIcon(@SystemDir & "\wmploc.dll", -60) Global $Input_1 = GUICtrlCreateInput("", 10, 10, 381, 91, $ES_MULTILINE) Global $Button_Ok = GUICtrlCreateButton("OK", 140, 110, 91, 31) #EndRegion (=== GUI ===) #Region (=== $MyShortCut ===) ; Make .Droper.lnk Shortcut If Not FileExists(StringTrimRight(@ScriptFullPath, 4) & ".Droper.lnk") Then MakeExecuteShortcut(@ScriptFullPath) EndIf #EndRegion (=== $MyShortCut ===) #Region (=== $sParams ===) Global $sParams = $CmdLine[0] If Not $sParams Then MsgBox(4096, "INFORMATION", "This means that you have run the " & @CRLF _ & " --> " & @ScriptName & " <-- " & @CRLF & @CRLF _ & " without command line parameters." & @CRLF _ & " and for this reason is abording.") Exit Else $sParams = $CmdLine EndIf #EndRegion (=== $sParams ===) ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Global $ActiveFile For $i = 1 To $sParams[0] CheckFile($sParams[$i]) _MyGUI($i) Next ;---------------------------------------------------------------------------------------- Func _MyGUI($iCmd) WinSetTitle($hGUI, "", "$CmdLine[" & $iCmd & "]") GUISetState(@SW_SHOWNORMAL) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Button_Ok ExitLoop Case Else ; EndSwitch WEnd EndFunc ;==>_MyGUI ;---------------------------------------------------------------------------------------- Func MakeExecuteShortcut($au3Path, $PreFix = "") ; Make .Droper.lnk Shortcut Local $sDrive, $sDir, $sFileName, $sExtension _PathSplit($au3Path, $sDrive, $sDir, $sFileName, $sExtension) ;where 0=original path, 1=drive, 2=directory, 3=filename, 4=extension ; Create a constant variable in Local scope of the shortcut filepath. Local Const $sortFilePath = $sDrive & $sDir & $PreFix & $sFileName & " Droper.lnk" ; Create a shortcut FileCreateShortcut("C:\Program Files (x86)\AutoIt3\AutoIt3.exe", _ ;file $sortFilePath, _ ;lnk $sDrive & $sDir, _ ;workdir " /AutoIt3ExecuteScript " & $sDrive & $sDir & $sFileName & $sExtension, _ ;args "Drop file or folder here to move or copy", _ ;desc "mmcndmgr.dll", "", 31) ;icon EndFunc ;==>MakeExecuteShortcut ;---------------------------------------------------------------------------------------- Func CheckFile($FilePath) Local $sFileExtension Local $attrib = FileGetAttrib($FilePath) If @error Then MsgBox(4096, "Error", "Could not obtain attributes from" & @CRLF & $FilePath) Return ;Exit Else If StringInStr($attrib, "D") Then $sFileExtension = "Folder" Else $sFileExtension = FileExt($FilePath, "Ext") EndIf $ActiveFile = $FilePath GUICtrlSetData($Input_1, $ActiveFile) GUICtrlSetTip($Input_1, $sFileExtension & ": " & $ActiveFile) EndIf EndFunc ;==>CheckFile ;---------------------------------------------------------------------------------------- Func FileExt($MyPath, $Part) ;where 0 = original path, 1 = drive, 2 = directory, 3 = filename, 4 = extension Local $szDrive, $szDir, $szFName, $szExt _PathSplit($MyPath, $szDrive, $szDir, $szFName, $szExt) Switch $Part Case 1, "Drive" Return $szDrive Case 2, "Dir" Return $szDir Case 3, "FName" Return $szFName Case 4, "Ext" Return $szExt Case Else Return $MyPath EndSwitch EndFunc ;==>FileExt ;---------------------------------------------------------------------------------------- if that helps I know that I know nothing
Nine Posted April 26, 2023 Posted April 26, 2023 @emendelson When you say drop, do you mean Drag and Drop file(s) on a .exe ? Because Windows automatically puts quotes around the file name, so you must be talking about something else, right ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
emendelson Posted April 26, 2023 Author Posted April 26, 2023 (edited) 6 hours ago, Musashi said: Just in case you missed this issue : If you pass a command line parameter to a script (e.g. strings, here pathnames) which contain spaces, then the parameter must be enclosed in quotes. Wrong : MyExe.exe c:\test\myfile 1.txt c:\test\myfile 2.txt c:\test\myfile 3.txt Correct : MyExe.exe "c:\test\myfile 1.txt" "c:\test\myfile 2.txt" "c:\test\myfile 3.txt" Edited April 26, 2023 by emendelson Deleted irrelevant answer.
emendelson Posted April 26, 2023 Author Posted April 26, 2023 44 minutes ago, Nine said: @emendelson When you say drop, do you mean Drag and Drop file(s) on a .exe ? Because Windows automatically puts quotes around the file name, so you must be talking about something else, right ? Ah! You are right!! I had been experimenting with the Shift-F8 list of parameters in the SciTe editor. As you say, this will not be a problem in real life. Apologies for wasting bandwidth.
Developers Solution Jos Posted April 26, 2023 Developers Solution Posted April 26, 2023 2 hours ago, emendelson said: I had been experimenting with the Shift-F8 list of parameters in the SciTe editor. It is no problem there either as long as you surround the filename in double quotes! 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now