 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
laserman
Joined: 21 Jan 2008 Posts: 7
|
Posted: Thu May 15, 2008 7:43 pm Post subject: How to overwrite file regardless of extention |
|
|
I wrote this script to search a destination folder and overwrite an old file with the same name as the new file no matter what the extention. After it copies the new file into the destination folder, it deletes the file in the temporary folder. The problem I am having is trying to set it up to work on multiple files at one time. I tried using "Loop, parse" but I just seemed to have hit a brick wall. Can anyone help?
| Code: |
FileSelectFile, MyFilePath, 3, C:\Documents and Settings\User\Desktop\Temp folder\, Select a file to save ,
SplitPath, MyFilePath,,,, NewFileName, ;Gets only the file name, no ext.
if MyFilePath =
MsgBox, The user didn't select anything.
else
{
IfExist, C:\Documents and Settings\User\Desktop\To Folder\%NewFileName%.* ; Checks if the filename exists in the destination folder.
{
MsgBox, 4,, At least one previous file with that name exists. Would you like to continue?
IfMsgBox Yes
{
FileDelete, C:\Documents and Settings\User\Desktop\To Folder\%NewFileName%.* ; Deletes the old file in the destination folder.
FileCopy, %MyFilePath%, C:\Documents and Settings\User\Desktop\To Folder\ ; Copies the new file to the destination folder.
MsgBox, %NewFileName% was saved.
FileDelete, %MyFilePath% ; Deletes the copy of the new file in the temp folder.
ExitApp
}
else
ExitApp
}
else
FileCopy, %MyFilePath%, C:\Documents and Settings\User\Desktop\To Folder ; Copies the new file to the destination folder.
FileDelete, %MyFilePath% ; Deletes the copy of the new file in the temp folder.
MsgBox, %NewFileName% was saved.
}
;
; AutoHotkey Version: 1.0.47.04
; Language: English
;
; Script Function: Delete previous version of file and save new file regardless of extension.
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
|
|
|
| Back to top |
|
 |
heresy
Joined: 11 Mar 2008 Posts: 224
|
|
| Back to top |
|
 |
laserman
Joined: 21 Jan 2008 Posts: 7
|
Posted: Thu May 22, 2008 2:44 pm Post subject: |
|
|
Thanks for the help heresy. I used that command made a few tweaks and it's working like a charm.
| Code: | MsgBox, 3, Drawing Copy Utility, Do you have more than one file to copy?
IfMsgBox, Cancel
Exit
IfMsgBox, Yes
{
MsgBox, 4,Drawing Copy Utility, Are all drawings in the AAF INBOX? Clicking NO will exit.
IfMsgBox, No
Exit
Loop, C:\Documents and Settings\User\Desktop\Aaf Inbox\*
{
if A_LoopFileLongPath =
Exit
SplitPath, A_LoopFileLongPath,,,, NewFileName,
IfExist, W:\AAF DWGS\%NewFileName%.*
{
MsgBox, 4,Drawing Copy Utility, At least one previous file with the name %NewFileName% exists. Would you like to overwrite it?
IfMsgBox Yes
{
FileDelete, W:\AAF DWGS\%NewFileName%.*
FileCopy, %A_LoopFileLongPath%, C:\Documents and Settings\User\Desktop\Network
MsgBox, %NewFileName% was saved to the network.
FileDelete, %A_LoopFileLongPath%
}
}
else
{
FileCopy, %A_LoopFileLongPath%, C:\Documents and Settings\User\Desktop\Network
FileDelete, %A_LoopFileLongPath%
MsgBox, %NewFileName% was saved to the network.
}
}
}
else
FileSelectFile, MyFilePath, 3, C:\Documents and Settings\User\Desktop\Aaf Inbox\, Select a drawing file to save to network,
if MyFilePath =
Exit
else
SplitPath, MyFilePath,,,, NewFileName,
IfExist, W:\AAF DWGS\%NewFileName%.*
{
MsgBox, 4,Drawing Copy Utility, At least one previous file with that name exists. Would you like to continue?
IfMsgBox Yes
{
FileDelete, W:\AAF DWGS\%NewFileName%.*
FileCopy, %MyFilePath%, C:\Documents and Settings\User\Desktop\Network
MsgBox, %NewFileName% was saved to the network.
FileDelete, %MyFilePath%
ExitApp
}
else
ExitApp
}
else
FileCopy, %MyFilePath%, C:\Documents and Settings\User\Desktop\Network
FileDelete, %MyFilePath%
MsgBox, %NewFileName% was saved to the network.
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|