icadea Posted November 12, 2007 Posted November 12, 2007 Hi all, This is the code below i'm havin currently, Func PrnscrO() Global $hBMPO, $fsaveO _Clip_Empty () $hBMPO = _ScreenCap_Capture ("", 0, 0, -1, -1, False) $fsaveO = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) & ".jpg" If @error Then Return If FileExists($fsaveO) Then MsgBox(4096, $fsaveO, "File Exists, Please rename") Else EndIf _Clip_SetData ($hBMPO) _ScreenCap_SaveImage ($fsaveO, $hBMPO) What i would like to know is , 1) How could I loop the filesavedialog in case the same filename exist. Right now it only says the same filename exist and returns back to the main function. What is needed, when the program finds same file name exist, it should prompt message. When ok is clicked a rename filesavedialog is shown/ or the same filesavedialog is shown till the same name does not exist in the directory to be saved. Is this possible? I've searched the forum and could not find. Pls help or show the way, thanks
PsaltyDS Posted November 12, 2007 Posted November 12, 2007 Just put it in a loop that doesn't exit until you get what you want: Func PrnscrO() Global $hBMPO, $fsaveO _Clip_Empty () $hBMPO = _ScreenCap_Capture ("", 0, 0, -1, -1, False) While 1 $fsaveO = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) & ".jpg" If @error Then Return If FileExists($fsaveO) Then MsgBox(4096, $fsaveO, "File Exists, Please rename") Else ExitLoop EndIf WEnd _Clip_SetData ($hBMPO) _ScreenCap_SaveImage ($fsaveO, $hBMPO) P.S. It's not generally good practice to declare global variables insid a function. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
icadea Posted November 12, 2007 Author Posted November 12, 2007 Thanks for the help,it works great. I have changed the global variables declaration outside the function. Thanks again for your quick help.
icadea Posted November 16, 2007 Author Posted November 16, 2007 sorry to reopen the thread, just noticed a small issue while troubleshooting. 1) Screen capture and save(given name test) 2) File is saved as test.jpg but on the next 3) Screen capture and save(click on test.jpg) 4) File exist prompt(Press YES to replace and SAVE) When this is done the older file test.jpg and the new file test.jpg.jpg exist. $fsaveO = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) & ".jpg" Is it possible once the file is renamed the old file is replaced completely instead or creating a clone. Searched the forum on Filedialogsave but none seems to help on file extension Pls point me to the right direction so i could learn from there. thanks
MrCreatoR Posted November 16, 2007 Posted November 16, 2007 You might want to use file name that user type, but the existing file always rename (programly)?Try this:Func PrnscrO() Global $hBMPO, $fsaveO _Clip_Empty () $hBMPO = _ScreenCap_Capture ("", 0, 0, -1, -1, False) While 1 $fsaveO = FileSaveDialog("Choose a name and location to save.", @WorkingDir, "Jpg (*.jpg)", 18) If @error Then Return If StringRight($fsaveO, 4) <> ".jpg" Then $fsaveO &= ".jpg" If FileExists($fsaveO) Then Local $sFile = StringRegExpReplace($fsaveO, "^.*\\", "") Local $NewFileName = _GetNewFileName($sFile, @WorkingDir) FileMove($fsaveO, @WorkingDir & "\" & $NewFileName) EndIf ExitLoop WEnd _Clip_SetData ($hBMPO) _ScreenCap_SaveImage ($fsaveO, $hBMPO) EndFunc Func _GetNewFileName($sFile, $dDir, $Delim1 = " (", $Delim2 = ")") If Not FileExists($dDir & "\" & $sFile) Then Return $sFile $dDir = StringRegExpReplace($dDir, "\\ *$", "") Local $sName = StringRegExpReplace($sFile, "\.[^.]*$", "") Local $sExtn = StringMid($sFile, StringLen($sName) +1) Local $i = 1, $dFile = $sFile While FileExists($dDir & "\" & $dFile) $dFile = $sName & $Delim1 & $i & $Delim2 & $sExtn $i += 1 WEnd Return $dFile EndFuncSo the old file will be always renamed to file(1).jpg, file(2).jpg etc. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
icadea Posted November 17, 2007 Author Posted November 17, 2007 thanks so much, this will give me some ideas. thanks again
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