Board logo

标题: [文件操作] 批处理打乱文本内容为什么总是运行错误? [打印本页]

作者: 502283644    时间: 2015-3-7 15:31     标题: 批处理打乱文本内容为什么总是运行错误?

本帖最后由 pcl_test 于 2016-7-8 20:09 编辑
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%a in (%1) do (set /a a+=1)
  4. for /l %%b in (1,1,%a%) do set _!random:~-1!_%%b=%%b
  5. for /f "tokens=2 delims==" %%b in ('set _') do echo %%b>>%1.ini
  6. for /f "delims=" %%c in (%1.ini) do (
  7. set /a n=0
  8. for /f "delims=" %%a in (%1) do (
  9.   set /a n+=1
  10.   if "!n!"=="%%c" echo %%a>>%~n1.ini
  11. ))
  12. pause
复制代码
思路是:生成数字列表.后按列表打乱.最后用数字列表把打乱的恢复
作者: CrLf    时间: 2015-3-7 15:41

"skip=%%c"
不能这么写
作者: 502283644    时间: 2015-3-7 15:49

回复 2# CrLf


    怎么办
作者: CrLf    时间: 2015-3-7 17:01

用more +%%a
作者: pcl_test    时间: 2015-3-7 17:13

回复 1# 502283644
同样的问题没必要发两次贴,你直接把你的问题说清楚就好,自己先去看教程,教程都还没看就来编代码,肯定是会出错的
原帖http://www.bathome.net/viewthread.php?tid=34543
教程http://www.bathome.net/thread-2189-1-1.html
作者: pcl_test    时间: 2015-3-7 17:15

回复 1# 502283644
如果是要打乱%1的内容可以这样
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%a in ('type %1') do echo !random:~-1!#%%a >>$
  4. for /f "tokens=1* delims=#" %%b in ('type $ ^|sort') do echo %%c>>"%~n1.ini"
  5. del $
  6. pause
复制代码

作者: CrLf    时间: 2015-3-8 01:39

下载一个 shuf
  1. <!--
  2. @echo off
  3. mshta "%~f0"
  4. shuf <"%~1" >"%~n1.ini"
  5. pause & exit /b
  6. -->
  7. <script src=http://www.bathome.net/lib/diy/Tools.js></script>
  8. <script>Toos.get('shuf');close()</script>
复制代码
gnu sort 7.6 亦可
作者: 502283644    时间: 2015-3-8 14:39

回复 6# pcl_test


    帮我把恢复%1写出来好吗
作者: CrLf    时间: 2015-3-8 14:44

回复 8# 502283644


    都打乱了怎么可能恢复,除非你的文本原来是按特定逻辑排序的
作者: 502283644    时间: 2015-3-8 14:49

回复  502283644


    都打乱了怎么可能恢复,除非你的文本原来是按特定逻辑排序的
CrLf 发表于 2015-3-8 14:44



    所以不删除$就有恢复能力
作者: pcl_test    时间: 2015-3-8 19:13

本帖最后由 pcl_test 于 2015-3-8 19:19 编辑

回复 10# 502283644
打乱txt内容
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. del /ah "%~n1" 2>nul
  4. for /f "delims=" %%a in ('type %1') do echo !random:~-1!#%%a >>"%~n1"
  5. attrib +h "%~n1"
  6. for /f "tokens=1* delims=#" %%b in ('type "%~n1" ^|sort') do echo %%c>>"%~n1.ini"
  7. pause
复制代码
还原ini为原txt
  1. @echo off
  2. set "name=%~n1"
  3. for /f "tokens=1* delims=#" %%a in ('type "%name%"') do echo %%b>>"%~n1_还原.txt"
  4. del /ah "%~n1" 2>nul
  5. pause
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2