How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

Get help with using AutoHotkey and its commands and hotkeys
cadudesun
Posts: 60
Joined: 04 Jun 2016, 10:26

How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

20 Nov 2018, 04:57

Hi,

I'd appreciate your help.

For clipboard contents having file paths with the \OneDrive\ (e.g. Z:\!CLOUD\OneDrive\File.pdf), I would like to paste content replacing the file path with: %OneDrive%\File.pdf

The operating would:
1- ignore everything to the left of \OneDrive\
2- insert this folder between % (%OneDrive%)
3- append the remaining file path to the right (\File.pdf)
4- generating: %OneDrive%\File.pdf

Thank you very much!
User avatar
Bugz000
Posts: 41
Joined: 30 Sep 2013, 10:01

Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

20 Nov 2018, 23:57

https://autohotkey.com/docs/commands/InStr.htm


untested, probably doesn't work out of box but hopefully you get the idea

Code: Select all

#singleinstance, force
#persistent
OnClipboardChange("Filter")
return
filter:
Filter()
return


filter()
{
	if instr(clipboard, "\OneDrive")
		o := StrReplace(Clipboard, "\OneDrive\", "`%OneDrive`%")
	msgbox % o
}
Image
SunAndSuch
Posts: 41
Joined: 05 Oct 2015, 12:11

Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

21 Nov 2018, 06:04

Maybe

Code: Select all

filePath:="Z:\!CLOUD\OneDrive\File.pdf"
MsgBox,% RegExReplace(filePath,"^.*\\OneDrive\\(.*)","%OneDrive%\$1")
Windows 10, Ahk v1 x64-bit.
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

21 Nov 2018, 06:31

This one works if you only copy one filename at a time

Code: Select all

words := StrSplit(clipboard, "\")
Loop % words.MaxIndex()
{
    this_word:= words[A_Index]
	if a_index = 4
	need = %this_word%
}
result = %OneDrive%\%need%
msgbox %result%
exitapp
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

21 Nov 2018, 06:49

If you have something like this in your clipboard:
Z:\!CLOUD\OneDrive\File1.pdf
Z:\!CLOUD\OneDrive\File2.pdf
Z:\!CLOUD\OneDrive\File3.pdf
Z:\!CLOUD\OneDrive\File4.pdf
Z:\!CLOUD\OneDrive\File5.pdf

This code will only give four replacements.

Code: Select all

words := StrSplit(clipboard, "\")
qty := 1
wrd := 4
Loop % words.MaxIndex()
{
    this_word:= words[A_Index]
	if a_index = %wrd%
	{
		result%qty% = %this_word%
	qty += 1
	wrd += 3
	continue
		if ErrorLevel = 0
			break
	}
}

outcome = %OneDrive%\%result1%`n%OneDrive%\%result2%`n%OneDrive%\%result3%`n%OneDrive%\%result4%`n
StringReplace, outcome, outcome,Z:,,all
StringReplace, outcome, outcome,`n,,all
msgbox %outcome%
exitapp
SunAndSuch
Posts: 41
Joined: 05 Oct 2015, 12:11

Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"

21 Nov 2018, 09:26

Well, if you want it in a loop:

Code: Select all

;Let's pretend clip is Clipboard
clip:=
(
"Z:\!CLOUD\OneDrive\File1.pdf
Z:\!CLOUD\OneDrive\File2.pdf
Z:\!CLOUD\OneDrive\File3.pdf
Z:\!CLOUD\OneDrive\File4.pdf
Z:\!CLOUD\OneDrive\File5.pdf"
)
Loop,Parse,clip,`n,`r
	res.=RegExReplace(A_LoopField,"^.*\\OneDrive\\(.*)","%OneDrive%\$1") "`r`n"
MsgBox,% SubStr(res,1,-2)
gives:
%OneDrive%\File1.pdf
%OneDrive%\File2.pdf
%OneDrive%\File3.pdf
%OneDrive%\File4.pdf
%OneDrive%\File5.pdf
Windows 10, Ahk v1 x64-bit.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Helgef and 167 guests