FileCopyDir - overwrite every sub-folder except one

Get help with using AutoHotkey and its commands and hotkeys
MapleStreet
Posts: 5
Joined: 06 Oct 2016, 03:38

FileCopyDir - overwrite every sub-folder except one

11 Dec 2019, 06:07

Hey,

i want to copy a Folder every time i start the Script. In this folder are 10 sub-folders.
I want to copy the content of the folder but he shoudnt overwrite one sub-folder.

How do i do this?

I use

FileCopyDir D:\%Name%\ , C:\%Name%\,1


How can i tell him to not overwrite a sub-folder named "INI"?

Do i have to use 10x FileCopyDir for the 10 sub-folders and use 9x the "1" parameter for overwrite and 1x the "0" parameter to not overwrite?


FileCopyDir D:\%Name%\1\ , C:\%Name%\1\,1
FileCopyDir D:\%Name%\2\ , C:\%Name%\2\,1
FileCopyDir D:\%Name%\3\ , C:\%Name%\3\,1
FileCopyDir D:\%Name%\4\ , C:\%Name%\4\,1
...
FileCopyDir D:\%Name%\INI\ , C:\%Name%\INI\,0
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: FileCopyDir - overwrite every sub-folder except one

11 Dec 2019, 09:15

I'm not sure which you want...

The first script uses ternary to switch the "Overwrite" flag between 1 or 0 depending on if the folder name is "INI" or not.

The second script will just skip copying the INI folder completely, and copy the other folders only.

Hope that helps!

Code: Select all

#SingleInstance, Force

Name := "Test"

Loop, Files, J:\%Name%\*.*, D
{
	FileCopyDir, % A_LoopFileLongPath, % StrReplace(A_LoopFileLongPath, "J:\", "C:\"), % (A_LoopFileName = "INI" ? 0 : 1)
}

Code: Select all

#SingleInstance, Force

Name := "Test" ; Folder Name

Loop, Files, D:\%Name%\*.*, D
{
	If (A_LoopFileName = "INI") {
		Continue
	}
	
	FileCopyDir, % A_LoopFileLongPath, % StrReplace(A_LoopFileLongPath, "D:\", "C:\"), 1
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
MapleStreet
Posts: 5
Joined: 06 Oct 2016, 03:38

Re: FileCopyDir - overwrite every sub-folder except one

12 Dec 2019, 05:27

great, both works.

but what about the files in my main folder? :D

this one only copies the sub-folders.
MapleStreet
Posts: 5
Joined: 06 Oct 2016, 03:38

Re: FileCopyDir - overwrite every sub-folder except one

12 Dec 2019, 05:36

i solved it this way.
now iam working with extension

Loop, Files, J:\*, R
FileCopy, % A_LoopFileLongPath, % StrReplace(A_LoopFileLongPath, "J:\", "C:\"), % (A_LoopFileExt = "ini" ? 0 : 1)
MapleStreet
Posts: 5
Joined: 06 Oct 2016, 03:38

Re: FileCopyDir - overwrite every sub-folder except one

12 Dec 2019, 09:34

my method doesnt work that well...

now it only copies files into the sub-folders if they already exist. but if there is no sub-folder then he doesnt copy the files into it

Return to “Ask For Help”

Who is online

Users browsing this forum: artur1884, Rohwedder, zavf and 37 guests