Sign in to follow this  
Followers 0
dRsrb

FileMove() doesn't move files because of _GDIPlus_ImageLoadFromFile()

5 posts in this topic

Hi! :)

It took me an hour to find out, that FileMove() doesn't work in _Example1(). But what's the reason?

#Include <GDIPlus.au3>

$sSource = 'C:\Wallpaper\AnyImage.jpg'
$sDest  = 'C:\Wallpaper\16_10\AnyImage.jpg'

_Example1()
;~ _Example2()

Func _Example1()
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sSource)
    _GDIPlus_ShutDown()
    FileMove($sSource, $sDest, 1 + 8)
EndFunc

Func _Example2()
    FileMove($sSource, $sDest, 1 + 8)
EndFunc

I wrote a small script to sort wallpapers by their aspect ratio (16:10, 16:9, 4:3, ...), but it doesn't work, because FileMove() doesn't move any images to the desired destination. At least it creates the directory structure.What could be the solution for this problem? _Example2() works as expected.

My system:

- AutoIt v3.3.6.1

- SciTE v1.79

- Windows 7 Ultimate (64-Bit)

Bye

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You probably have the file OPEN which will make a Move of the file fail? (Not looked at the GDI funcs so am not sure how they use the file)

You should test the Return value from the FileMove(0 to ensure it was successful.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use _GDIPlus_ImageDispose($hImage)

Edit: Also the latest version of SciTE4AutoIt3 isn't V1.79 but V2.27.

#include <GDIPlus.au3>

$sSource = 'GPLV3.png'
$sDest = 'GPLV3r.png'

_Example1()
;~ _Example2()

Func _Example1()
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sSource)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    FileMove($sSource, $sDest, 1 + 8)
EndFunc   ;==>_Example1

Func _Example2()
    FileMove($sSource, $sDest, 1 + 8)
EndFunc   ;==>_Example2
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Hey Jos & guinness! :)

Yes, you're right! The file is locked and _GDIPlus_ImageDispose() solves the prob - thank you very much! ;))

Bye

Share this post


Link to post
Share on other sites

You're welcome.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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

  • Similar Content

    • climmax
      By climmax
      Hi all,
      As a newby i need some help.
      I am trying to add time stamps to file names.
      But it has to do it only once. So i made a check on lenght of filename.
      If filename extention and Lenght  is correct it renames the file with a time stamp.
      I use a ini file for settings. and extentions what needs to be renamed.
      The script works but only once.
      it renames all the  files that are in the ini . like test.txt to text050102.txt
      But when there is 2 files. Like test.txt and  text050102.txt
      It does not rename the test.txt file
      where am i doing this wrong?
       
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> $path = IniRead("RenameFiles.ini","General","InputFolder","Error") $TimeOption = IniRead("RenameFiles.ini","General","TimeOption","Error") Local $aArray = iniReadSection("RenameFiles.ini","EXT") For $i = 1 To $aArray[0][0] $search01 = FileFindFirstFile($path&"*"&$aArray[$i][0]) If $aArray="" Then MsgBox(0,"Error","Check RenameFiles.ini","","") Exit EndIf While 1 $File = FileFindNextFile($search01) $StringLenght= StringLen ($File) if $StringLenght= $aArray[$i][1] Then $FileSplit= StringSplit($File,".") $Time=FileGetTime ( $File ,$TimeOption ,0 ) If @error Then ExitLoop FileMove($path & $File, $path & $FileSplit[1] & $Time[3] & $Time[4] & $Time[5] & $aArray[$i][0], 0) Else ExitLoop EndIf WEnd FileClose($search01) next Ini file looks like:
      [General] ;Enter folder where the files are located: ;Example C:\test\ InputFolder=C:\FileRename\ ;Enter the option you want to use, for timestamp ;0 = Last modified (default) ;1 = Created ;2 = Last accessed TimeOption=0 ;Enter Files extensions that needs a timestamp. ;FileExtention=FileNameLenght (characters) ;Example .TRX.MAU (Dont forget the leading point) ;FileNameLenght = how many characters the filename contains. Including "." ;If filename is longer or shorter it wil not rename the file. ;Example TR150730.TRX.MAU = 16 characters. [EXT] .txt=8 .log=8  
    • megaservo
      By megaservo
      Hi All, 
      I'm making a stage 1 preparation script to apply to target worksation Win 7 and Win 8.1 machines -in preparation to running a separate batch script later (stage 2) within our Windows Server with "netdom.exe move" xxxxxxxx
      Stage 1 Script Tasks: 
      1. delete some common shortcuts
      2. Then move all files within common user profile backup locations - including any files in the sub-directories of the common backups locations within each users profile folder. 
      Stage 1 Script Purpose: 
      Make it easy for staff to grab files and folders from one C:\_Backup directory
      Stage 1 Script PROBLEM:
      The script successfully removes the desired shortcuts - that part works well.
      Problem is it only copies files in root directory of each users common folder (eg: Desktop) but doesn't move all the sub-directories and its files and move it to the corresponding backup directory. I've searched the whole AutoIT forum domain for ideas but I've hit a dead end. 
       
      Here is the code: 
      ;START TASKS-------------------------------------------------------------------------- #include <FileConstants.au3> $ccsystem32 = @SystemDir ;define C:\Windows\System32 folder $ccdesktop = @DesktopCommonDir ;define all users desktop location ;rename CompanyName Remote Desktop shortcut FileCopy($ccdesktop&"\Remote Desktop.rdp", $ccdesktop&"\Company Remote Desktop.rdp", 0) ;delete copies of "SHIP", "eKeySilent", "eKey Manual Login", "eKey Admin" and "ConnX Login" from every profile, adds a copy ot each Desktop folder. $folder = StringLeft(@UserProfileDir,StringInStr(@UserProfileDir,"\",0,-1)) $search = FileFindFirstFile($folder&"*") While 1 $profile = FileFindNextFile($search) If @error Then ExitLoop If FileExists($folder&$profile&"\desktop\SHIP.url") Then FileDelete($folder&$profile&"\desktop\SHIP.url") EndIf If FileExists($folder&$profile&"\desktop\ekeySilent.lnk") Then FileDelete($folder&$profile&"\desktop\ekeySilent.lnk") EndIf If FileExists($folder&$profile&"\desktop\eKey Manual Login.url") Then FileDelete($folder&$profile&"\desktop\eKey Manual Login.url") EndIf If FileExists($folder&$profile&"\desktop\ConnX Login.lnk") Then FileDelete($folder&$profile&"\desktop\ConnX Login.lnk") EndIf If FileExists($folder&$profile&"\desktop\eKey Admin.url") Then FileDelete($folder&$profile&"\desktop\eKey Admin.url") EndIf If FileExists($folder&$profile&"\desktop\Remote Desktop.rdp") Then FileDelete($folder&$profile&"\desktop\Remote Desktop.rdp") EndIf ;backup desktop folder of each user If FileExists($folder&$profile&"\desktop\"&"*.*") Then FileMove($folder&$profile&"\desktop\"&"*.*", "C:\_Backup\"&$profile&"\Desktop\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup downloads folder of each user If FileExists($folder&$profile&"\downloads\"&"*.*") Then FileMove($folder&$profile&"\downloads\"&"*.*", "C:\_Backup\"&$profile&"\Downloads\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup Documents folder of each user If FileExists($folder&$profile&"\documents\"&"*.*") Then FileMove($folder&$profile&"\documents\"&"*.*", "C:\_Backup\"&$profile&"\Documents\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup pictures folder of each user If FileExists($folder&$profile&"\pictures\"&"*.*") Then FileMove($folder&$profile&"\pictures\"&"*.*", "C:\_Backup\"&$profile&"\Pictures\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup music folder of each user If FileExists($folder&$profile&"\music\"&"*.*") Then FileMove($folder&$profile&"\music\"&"*.*", "C:\_Backup\"&$profile&"\Music\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup videos folder of each user If FileExists($folder&$profile&"\videos\"&"*.*") Then FileMove($folder&$profile&"\videos\"&"*.*", "C:\_Backup\"&$profile&"\Videos\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup IEfavorites folder of each user If FileExists($folder&$profile&"\favorites\"&"*.*") Then FileMove($folder&$profile&"\favorites\"&"*.*", "C:\_Backup\"&$profile&"\IEFavorites\", 9) ;flag combining overwrite existing files & create destination structure EndIf WEnd FileClose($search) ;end of deletion of old shortcuts and copying of user files in backup directories. I tried DirMove but I can confirm that windows wont let me move the whole eg: Desktop folder as its read only and I obviously dont want to screw up that account as well (in case we need to log into it) - so I don't want to for example delete the actual Desktop directory. Just move  
      I dont know how to move only all the sub-directories of all the above folders eg: Desktop - and not move the directory eg: Desktop itself. is it 2 problems?
      sub-directories are read only? DirMove is not allowed to copy any sub-directories?  Reason why I was asked to use FileMove and DirMove is that we are concerned of running out of C drive space if we use FileCopy and DirCopy (works on eg: Desktop dir)
      How file structure of C:\_Backup should look like on each target workstation system:
      but it should not move the for eg: C:\Users\Admin\Desktop but should move all of its files and folders. Why move not copy? C drive space is limited on each workstation, so I don't want to create double the files.  Example of Desired File structure of backup directory: C:\_Backup\ C:\_Backup\Admin\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Administrator\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Administrator.DomainName\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Default\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Default User\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\User1 .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Public\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) Anybody has any ideas or assistance? 
      Might be a really simple thing that I missed. 
      Something missing to the while loop? Maybe the whole while loop needs to be redesigned? ???
       
    • owensct
      By owensct
      Hi All,

      I've got a head scratcher that I am hoping someone could help me with as I'm trying to finsih up some code for our HR department that I need to put into production by Monday morning.

      I have written a Autoit script that shuts down a database engine and then does a copy of the database to a folder on the database server. Unfortunately the backup space on the server is limited so I have been manually moving the backups to another server twice a week until I could find the time to automate the move of the files and folders as part of the script. Well the time to automate it is this weekend per my CIO.

      Because the end users may do multiple backups in a given day, I have assigned the month-day-year_hours-minutes-seconds to a variable and I rename the initial backup folder and logfile by appending the datetime variable to them. So the folder Daily_ becomes Daily_06302012_192515 and Daily_.log becomes Daily_06302012_192515.log. Using the FileMove function I have been able to get it to move the log file but for the life of me I can't get it to move the folder . So I tried to use DirMove, but I can't get it to work either. The process runs, but the folder in still on the original server when it finishes. The code I am using to try and accomplish this is as follows:

      $datetime = @MON & @MDAY & @YEAR & "_" & @hour & @min & @SEC
      RunWait('PsExec \\RHP-VMS-001 robocopy "\\RHP-VMS-001\ANSOSONESTAFF\DATA" "\\Rhp-vms-001 Staff_backups\OS_Daily\daily_" /COPYALL /S /E /V /LOG+:"
      RunWait(@comspec & " /c ren \\rhp-vms-001\staff_backups\OS_Daily\daily_ Daily_" & $datetime)
      RunWait(@comspec & " /c ren \\Rhp-vms-001\staff_backups\OS_Daily\Daily_.log Daily_" & $datetime & ".log")
      RunWait('sc \\RHP-VMS-001 start "Pervasive.SQL (relational)"', '', @SW_HIDE, 2)
      RunWait('sc \\RHP-VMS-001 start "Pervasive.SQL (transactional)"', '', @SW_HIDE, 2)
      FileMove("\\rhp-vms-001\staff_backups\OS_Daily\*.*", "\\rhp-diskbackup\onestaff\OSTest_Daily")
      DirMove("\\rhp-vms-001\staff_backups\OS_Daily\Daily_" & $datetime, "\\rhp-diskbackup\onestaff\OSTest_Daily")
      Else
      MsgBox(0,"One Staff Backup", "Database engine is down please contact the IS Department")
      Exit
      etc
      etc

      Any help is greatly appreciated as I can;t seem to fignure out what I'm doing wrong.

      Thanks

      Gordon
    • johnmcloud
      By johnmcloud
      The FileMove command is simple


      FileMove("C:Test", "D:Test")
      But if i want to use it with different dir, for example put it in "SendTo" dir? Like a script .bat. So the first dir change, and the second is always the same. It's possible?

      Thanks