Cannot Copy File - A_LastError 123 despite valid path - windows

I have a section of code that copies files with an incremented suffix in the file name that is failing to copy the files.
Example files names:
test-A.SLDPRT
test-1.SLDPRT
Before attempting to copy I have confirmed that both the current file pattern and new file pattern exist and do not exist respectively. However the FileCopy command results in A_LastError = 123 for invalid name. I then go manual copy and increment the suffix and test if that file pattern exists using FileExist() and it confirms that the file exists. This does not make sense to me and suggests that somehow the input for FileExist() and FileCopy() cannot be in the same format. The file pattern that I input into FileExist() to confirm if the file exists should be the same as the new pattern for FileCopy correct? Can anyone identify what might be the reason for the invalid name error?
!r::
clipSave := Clipboard
Clipboard :=
SendInput, ^{c}
ClipWait
Clip1 := Clipboard
; Grab File name, path and revision index
arrFiles := StrSplit(Clip1, [".SLDDRW", ".SLDPRT"])
;Msgbox % "File 1: " . arrFiles[1] . "`nFile 2: " . arrFiles[2]
str := arrFiles[1]
SplitPath, str, fName, fDir
;MsgBox % "Input: " str "`nFile Name: " fName "`nDirectory: " fDir
nameSplit := StrSplit(fName, [".", "-"])
rev := nameSplit[nameSplit.Length()]
; part number before the revision
partNum := StrSplit(fName, rev)
partNum := partNum[1]
; Increase the revision index
rev1 := rev
if (rev+0) {
; Rev up numeric based revision notation
rev := rev + 1
} else {
; Rev up alphabet based revision notation
rev := Substr(rev, 1, StrLen(rev)-1) . Chr(Asc(SubStr(rev, 0))+1)
}
;MsgBox % "Part No: " partNum "`nRev Old: " rev1 "`nRev New: " rev
; Copy the files with the new revision index
Msgbox % "Copy: " fDir . "\" . fName . ".SLDPRT" . "`nPaste: " . fDir . "\" . partNum . rev . ".SLDPRT"
oldPath := fDir . "\" . partNum . rev1
newPath := fDir . "\" . partNum . rev
;test if the old and new paths exist
if FileExist(fDir . "\" . partNum . rev1 . ".SLDPRT") {
MsgBox % "Exists! `n" . oldPath . ".SLDPRT"
} else {
Msgbox % "Does not exist :(`n" . oldPath . ".SLDPRT"
}
if FileExist(newPath . ".SLDPRT") {
MsgBox % "Exists! `n" . newPath . ".SLDPRT"
return
} else {
Msgbox % "Does not exist :(`n" . newPath . ".SLDPRT"
}
; Copy the files
FileCopy, fDir . "\" . partNum . rev1 . ".SLDPRT", newPath . ".SLDPRT"
MsgBox % "Copy Complete`nErrorLevel: >" A_lastError "<"
FileCopy, fDir . "\" . partNum . rev1 . ".SLDDRW", newPath . ".SLDDRW"
MsgBox % "Copy Complete`nErrorLevel: >" A_lastError "<"
Clipboard := clipSave
return

Related

Creating map function in Red language

How can I create map, a higher order function, in Red language. It should take a block and a function as arguments and apply the sent function to each member of block. I tried following code:
Red []
mapfn: function[blk sfn][
outblk: copy []
foreach i blk[
append outblk (sfn i) ]
outblk ]
; to test:
myblk: [" this " " is " " a " " line " "for" " testing " " only "]
probe mapfn myblk 'reverse
probe mapfn myblk 'trim
But it is not working - it simply sends back the original block without changing it or giving any error message. How can this be corrected?
In Rebol you have the mezzanine function apply
>> help apply
USAGE:
APPLY func block /only
DESCRIPTION:
Apply a function to a reduced block of arguments.
APPLY is a function value.
ARGUMENTS:
func -- Function value to apply (Type: any-function)
block -- Block of args, reduced first (unless /only) (Type: block)
REFINEMENTS:
/only -- Use arg values as-is, do not reduce the block
(SPECIAL ATTRIBUTES)
throw
See source apply.
As long as Red has no native apply you can write your own mapping function e.g
mapfn: function[blk sfn][
outblk: copy []
foreach i blk[
append outblk sfn copy i
]
outblk
]
Get the function with :functionname
>> myblk: [" this " " is " " a " " line " "for" " testing " " only "]
== [" this " " is " " a " " line " "for" " testing " " only "]
>> probe mapfn myblk :reverse
[" siht " " si " " a " " enil " "rof" " gnitset " " ylno "]
== [" siht " " si " " a " " enil " "rof" " gnitset " " ylno "]
>> probe mapfn myblk :trim
["this" "is" "a" "line" "for" "testing" "only"]
== ["this" "is" "a" "line" "for" "testing" "only"]
>>
An alternative and better way as you can not copy all datatypes is e.g.
mapfn: function[blk sfn][
collect [
foreach i blk[
keep sfn i
]
]
]
and call the function this way if no do not want to modify the original
mapfn newblk: copy/deep myblk :reverse

Explanation of default vimrc file for windows version of vim

I've just downloaded vim7.4 for windows and I'll like to know what the default vimrc file that comes with it is doing. Just a brief explanation of each item would be nice to know.
Here it is.
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
set nocompatible
By default, Vim behaves like its ancestor vi. It's not really a problem for quick edits but it seriously sucks if you intend to use it for more than 10 minutes. set nocompatible makes Vim more Vim-like than Vi-like.
See :help nocompatible.
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
Source those two files. vimrc_example.vim contains example settings. It may be a good idea to take a look at it: it may contain useful things for you.
behave mswin
mswin.vim contains a bunch of settings and mappings designed to make Vim work more or less like a typical Windows editor, like <C-v> to paste. This command "activates" that stupid behavior.
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
This is a function that defines Vim's behavior when used for diffing two or more buffers. It looks more like a hack than anything else, to me. It seems to be checking if your Windows environment is able to do the diff itself and, if not, use the builtin diff.
If you intend to use/learn Vim seriously, none of the above should go into your $HOME\_vimrc. Not even the first line since nocompatible is set automatically for you if Vim finds a $HOME\_vimrc.
I'm not really familiar with Windows so the diff part may be useful but you can safely drop the rest.
When you see a set something, do :help 'something (with the single quote).
You may have figured this out, but one thing you may want to add if you remove the vimrc_example.vim source is syntax on. Without this, text will be colorless in gvim regardless of colorscheme.

vim: execute shell command with variable and redirect output to new buffer

I want to call msbuild from the function below and redirect the output to a new buffer.
My problem is that I need to use a variable, for the filename, and therefore cant use '!' (can I?), and when I use exe or system() read complains that I'm not giving it a proper file.
func! myFunction()
let findstr = "findstr /s /m " . '"' . expand("%:t") . '"' . " *.vcxproj"
for project in split(system(findstr), nr2char(10))
echo "Building '" . project . "'"
let msbuild = "c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe" . " " . project . " " . "/t:rebuild /p:configuration=debug"
:tabnew | r system(msbuild) "<--THIS LINE HERE
endfor
endfunc
The :read command takes a file not a vim expression. However it can read in from standard output via :read !{cmd}. Example :%r!ls. Using the :execute command you can build your new command with your variable.
exe '%r!' . msbuild
Or you can use :put along with the expression register if you want to use an expression like system(). (Probably want to follow this with :0d_ to delete the first empty line)
put=system(msbuild)
Now it looks like you are trying to build your project and get a list of errors. I would recommend you look into :make, the 'makeprg' option, and the quickfix list as this is a more vim way of building a project.
For more help see:
:h :r!
:h :exe
:h :pu
:h #=
:h :make
:h 'makeprg'
:h quickfix
This is a function you can use to execute arbitrary shell commands and present their output in a new window ( you can put this in your _vimrc):
let s:lastcmd = ''
function! s:RunShellCommand(cmdline, bang)
" Support for repeating last cmd with bang:
let _ = a:bang != '' ? s:lastcmd : a:cmdline == '' ? '' : join(map(split(a:cmdline), 'expand(v:val)'))
if _ == ''
return
endif
let s:lastcmd = _
let bufnr = bufnr('%')
let winnr = bufwinnr(_)
" You can position the new window whenever you want, I chose below + right:
silent! execute winnr < 0 ? 'belowright new ' . fnameescape(_) : winnr . 'wincmd w'
" I could set buftype=nofile, but then no switching back and forth buffers.
" The results are presented just for viewing, not editing, modify at will:
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile wrap number
setlocal modifiable
silent! :%d
" Useful for debugging, if you encounter issues with fnameescape():
call setline(1, 'You entered: ' . a:cmdline)
call setline(2, 'Expanded to: ' . _)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !' . _
silent! execute 'autocmd BufUnload <buffer> execute bufwinnr(' . bufnr . ') . ''wincmd w'''
" If resizing is unwanted for commands with too much output, remove this line:
silent! execute 'autocmd BufEnter <buffer> execute ''resize '' . line(''$'')'
" You can use <localleader>r to re-execute the last command:
silent! execute 'nnoremap <silent> <buffer> <localleader>r :call <SID>RunShellCommand(''' . _ . ''', '''')<CR>'
execute 'resize ' . line('$')
setlocal nomodifiable
1
endfunction " RunShellCommand(cmdline)
command! -complete=shellcmd -nargs=* -bang Shell call s:RunShellCommand(<q-args>, '<bang>')
Use like:
:Shell gcc -ggdb -o test test.c && ./test

problem with directory name in awk

I am trying to write a script that takes 2 arguments : the first file contain some files extensions , and the second a directory .
My script move the files which their extension existed in the extension's file to the directory.
This is my script:
BEGIN{
}
{
file_ext = $1
folder = $2
isexist = "[ -e " $1 " ]"
if( ( system(isexist) ) != 0 )
{
getline < file_ext
system("find *." $0" -exec mv {} " folder " \;")
next
}
}
END{
}
But when I call the script in the shell , I am getting this error :
mv: missing destination file operand after `koko.cpp'
When I put folder name directly it works fine , but when I pass it by argument it doesn't work, why?
Command line arguments are accessed via the ARGV array:
BEGIN {
# "pop" the directory name off the arguments list
folder = ARGV[2]
ARGV[2] = ""
}
{
# then process the "file_ext" file
system("find . -name \\*." $0 " -exec mv {} " folder " \\;")
}

FFMPEG-PHP Windows "Can't open movie file"

ffmpeg extension is loaded as it is shown at phpinfo(), my file and script are at the same location, but I'm still getting this error.
Warning: Can't open movie file Untitled.avi in C:\xampp\htdocs\skelbiu\fetch.php on line 4
Fatal error: Call to a member function getDuration() on a non-object in C:\xampp\htdocs\skelbiu\fetch.php on line 5
My script:
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$ffmpegInstance = new ffmpeg_movie('Untitled.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();
I'm using php 5.2.9 (XAMPP 1.7.1), Windows 7.
Thanks in advance!
Your path to the movie has to be the full path. It doesn't matter where your script resides. Because you are using Win 7 and XAMPP, your path would be for example
$ffmpegInstance = new ffmpeg_movie('C:/xampp/htdocs/yourfolder/Untitled.avi');
I hope that this resolves your problem

Resources