批处理将文件侠内的文件名导入表格对应名称中
程序员文章站
2022-03-08 09:04:17
使用批处理实现将相片文件内的相片名称导入1表格对应名字中
方法一
/*&cls
@echo off
dir /b "相片\*.jpg"|cscript -n...
使用批处理实现将相片文件内的相片名称导入1表格对应名字中
方法一
/*&cls @echo off dir /b "相片\*.jpg"|cscript -nologo -e:jscript "%~f0" pause & exit/b */ var jpglist = ''; while(!wscript.stdin.atendofstream){ jpglist += wscript.stdin.readline()+'\r'; } var fd = new activexobject("scripting.filesystemobject").getfolder(".").path var objexcel = new activexobject("excel.application"); var objbook = objexcel.workbooks.open(fd+'\\1.xls'); objbook.worksheets(1).activate; var objsheet = objbook.activesheet; var cnt = objsheet.usedrange.rows.count; for(var i = 1; i<=cnt; i++) { var a1 = objsheet.cells(i, 1).value; var re = new regexp("[^\\r]*?"+a1+"[^\\r]*?\\.jpg","ig"); var m = jpglist.match(re); if(m)objsheet.cells(i, 2).value = m[0]; } objbook.saveas(fd+'\\2.xls'); objbook.close(); objexcel.quit();
方法二(更加简化些):
@echo off >$ dir /b "相片\*.jpg" (for /f "tokens=1 delims=, " %%a in (1.csv) do ( set /p"=%%a," findstr "%%a" $||echo; ))<nul>2.csv del $ pause