Page 1 of 1

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

Posted: 20 Nov 2018, 04:57
by cadudesun
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!

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

Posted: 20 Nov 2018, 23:57
by Bugz000
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
}

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

Posted: 21 Nov 2018, 06:04
by SunAndSuch
Maybe

Code: Select all

filePath:="Z:\!CLOUD\OneDrive\File.pdf"
MsgBox,% RegExReplace(filePath,"^.*\\OneDrive\\(.*)","%OneDrive%\$1")

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

Posted: 21 Nov 2018, 06:31
by hymal7
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

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

Posted: 21 Nov 2018, 06:49
by hymal7
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

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

Posted: 21 Nov 2018, 09:26
by SunAndSuch
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

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

Posted: 29 Nov 2018, 05:01
by cadudesun
Thanks all of you for the responses!