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!
How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
https://autohotkey.com/docs/commands/InStr.htm
untested, probably doesn't work out of box but hopefully you get the idea
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
}
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||
-
- Posts: 46
- Joined: 05 Oct 2015, 12:11
Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
Maybe
Code: Select all
filePath:="Z:\!CLOUD\OneDrive\File.pdf"
MsgBox,% RegExReplace(filePath,"^.*\\OneDrive\\(.*)","%OneDrive%\$1")
Windows 10, Ahk v1 x64-bit.
Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
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"
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.
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
-
- Posts: 46
- Joined: 05 Oct 2015, 12:11
Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
Well, if you want it in a loop:gives:
%OneDrive%\File1.pdf
%OneDrive%\File2.pdf
%OneDrive%\File3.pdf
%OneDrive%\File4.pdf
%OneDrive%\File5.pdf
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)
%OneDrive%\File1.pdf
%OneDrive%\File2.pdf
%OneDrive%\File3.pdf
%OneDrive%\File4.pdf
%OneDrive%\File5.pdf
Windows 10, Ahk v1 x64-bit.
Re: How replace clipboard content "Z:\!CLOUD\OneDrive\File.pdf" TO "%OneDrive%\File.pdf"
Thanks all of you for the responses!
Who is online
Users browsing this forum: Google [Bot] and 302 guests