http://bcn.bathome.net/s/tool/index.html?key=copyw
编译方法:
MinGW: g++ main.cpp -municode
MSVC : cl main.cpp /link shell32.lib
使用方法参见代码开头注释部分,支持从不同的目录复制文件到指定目录,支持Unicode字符
(在终端粘贴Unicode字符虽然看到是空白的,但是并没有丢失)
动机:有段时间帮别人复制电影,对方从N个不同目录选取,然后复制
不爽的地方就是频繁的复制粘贴,目录切换,如果不同时操作(卡卡卡),还要等待某部分复制完再继续
以及,我也写过一个Perl读取剪切板列表,直到遇到文件夹才开始复制的,进度条都是用字符串的…… 那感觉好累=_=- /*
- Code by: 523066680
- Date : 2015-11
- Compile:
- MinGW: g++ main.cpp -municode
- MSVC : cl main.cpp /link shell32.lib
- Usage:
- Example:
- main.exe D:\FA\* F:\Spare
- main.exe D:\FA\* D:\FB\name.iso F:\Spare
- main.exe "D:\FA\Pro・e.rar" "F:\Spare"
- Note:
- Last path is the destination
-
- Support: Copy from different folder, Unicode String
- */
-
- #include <cstdio>
- #include <cstdlib>
- #include <io.h>
- #include <windows.h>
-
-
- void ShellCopy( wchar_t *SRC, wchar_t *DST );
-
- void connect_wcs_array (
- wchar_t *buff,
- wchar_t *array[],
- int begin,
- int end
- );
-
- int wmain(int argc, wchar_t *argv[] )
- {
- if (argc < 3)
- {
- printf("Arguments not enough\n");
- return -1;
- }
-
- //argv[argc-1] - Destination
-
- int length = 0;
- for (int i = 1; i <= argc-2; i++)
- {
- length += wcslen( argv[i] ) + 1;
- }
- length++; // 0x00 0x00
-
- wchar_t *fwaits = (wchar_t *) malloc(
- length * sizeof(wchar_t) );
-
- connect_wcs_array( fwaits, argv, 1, argc-2 );
- ShellCopy( fwaits, argv[argc-1] );
- free(fwaits);
- return 0;
- }
-
- void ShellCopy( wchar_t *SRC, wchar_t *DST )
- {
- int sherr;
- SHFILEOPSTRUCTW op;
- ZeroMemory( &op, sizeof(op) );
- op.hwnd = NULL;
- op.wFunc = FO_COPY;
- op.pFrom = SRC;
- op.pTo = DST;
- op.fFlags= 0;
- sherr = SHFileOperationW( &op );
- printf("%x", sherr);
- }
-
- void connect_wcs_array (
- wchar_t *buff,
- wchar_t *array[],
- int begin,
- int end
- )
- {
- int i;
- wchar_t *pt = buff;
-
- for ( i = begin; i <= end; i++ )
- {
- wcsncpy( pt, array[i], wcslen(array[i]) + 1 );
- pt += wcslen(array[i]) + 1;
- }
- *(pt) = L'\0'; // append 0x00
- }
复制代码
|