[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 21# xczxczxcz

@echo on
setlocal enabledelayedexpansion
set num=100
for /f "delims=" %%i in ('dir /a-d /b /s *.*') do (
     rar a i:\hand\temp.rar %%i
     copy/y i:\hand\temp.rar i:\hand\!num:~-2!.rar
     set /a num+=1
     del i:\hand\temp.rar
   )
pause

代码我修改了,文件大小的判断我搞不定。能否增加文件夹判断的功能,谢谢!

TOP

回复 19# netdzb


    偶看你上面的 BAT 只处理 文件 没有处理文件夹。所以你懂的。过滤了文件夹。

TOP

本帖最后由 xczxczxcz 于 2019-6-17 17:24 编辑

把 XXX.PS1 放到你要处理的文件夹内。再把控制台切换到该目录。再运行。
偶看你自己写的BAT 也是在待处理文件夹内,所以也这样写了。

不过这样的话会把 xxx.ps1也打包进去。

其实你 在切换到该目录下后,直接把上面的 脚本内容 复制粘贴 到控制台运行 就可以了。

TOP

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>i:

I:\>cd \hetxt

I:\hetxt>path d:\power

I:\hetxt>powershell
Windows PowerShell V2 (Community Technology Preview - Features Subject to Change
)
Copyright (C) 2007 Microsoft Corporation. All rights reserved.

PS I:\hetxt> ./yan.ps1
PS I:\hetxt> ls


    Directory: Microsoft.PowerShell.Core\FileSystem::I:\hetxt


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         2019-6-17     13:54            yhgf
-a---          2019-6-1     12:50        133 hebing.bat
-a---          2019-6-2     11:30        117 hel.sh
-a---          2019-6-2     11:36        116 hel.sh.txt
-a---         2019-6-17     16:32         47 hello.ps1
-a---          2019-6-1     12:33        145 shiyan.bat
-a---         2019-6-17     16:21        254 test.bat
-a---          2019-6-2     11:31        100 total.txt
-a---         2019-6-17     17:12        341 yan.ps1
-a---          2019-6-1     11:58          8 密码01.txt
-a---          2019-6-1     11:58          8 密码02.txt
-a---          2019-6-1     11:58         10 密码03.txt
-a---          2019-6-1     11:58         11 密码04.txt
-a---          2019-6-1     11:59         10 密码05.txt
-a---          2019-6-1     11:59         12 密码06.txt
-a---          2019-6-1     11:59         11 密码07.txt
-a---          2019-6-1     11:59         14 密码08.txt

文件被打包了,文件夹yhgf没有被打包。

TOP

回复 15# xczxczxcz

代码运行了,结果不正确。文件夹下面的文件被压缩了。下面的子文件夹没有被打包。如果子文件下面还有子
文件夹还要继续被打包。

TOP

回复 15# xczxczxcz

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>i:

I:\>cd hetxt

I:\hetxt>path d:\power

I:\hetxt>powershell
Windows PowerShell V2 (Community Technology Preview - Features Subject to Change
)
Copyright (C) 2007 Microsoft Corporation. All rights reserved.

PS I:\hetxt> ./yan.ps1
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
The term 'rar' is not recognized as a cmdlet, function, operable program, or sc
ript file. Verify the term and try again.
At I:\hetxt\yan.ps1:7 char:3
+     & <<<<  rar a -ep $name $files[$Begin].FullName|Out-Null;
Get-Item : Cannot find path 'I:\hetxt\001.rar' because it does not exist.
At I:\hetxt\yan.ps1:8 char:15
+     if ((Get-Item <<<<  $name).Length/1MB -gt 20) {
PS I:\hetxt>

可以运行了,但是遇到rar找不到的问题,怎么解决?
控制台我能运行rar,环境变量我已经设置了啊。

TOP

回复  xczxczxcz

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

...
netdzb 发表于 2019-6-17 16:53



    holleo.ps1 前面加个 ".\"; powershell .\hello.ps1; 介样子。或 powershell "d:\xxx\hello.ps1"

TOP

回复 13# netdzb


    是 POWERSHELL 窗口  不是DOS 窗口

TOP

回复 12# netdzb

管理员运行 POWERSHELL 命令行窗口。
输入: set-executionpolicy RemoteSigned
回车,再输入 'A' 再回车。

输入: CD "你的文件夹目录完整路径" 回车。
粘贴上面的脚本内容,回车,会在目录下生成 001.ra;002.rar;....

如果你的 RAR 不能随意调用。则要把上面脚本中的 rar 写上完整路径。如: "C:\XXXX\XXX\WINRAR\RAR.EXE"

不需要 BAT 调用.

TOP

回复 8# xczxczxcz

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>d:

D:\>cd \power

D:\power>powershell hello.ps1
The term 'hello.ps1' is not recognized as a cmdlet, function, operable program,
or script file. Verify the term and try again.
At line:1 char:10
+ hello.ps1 <<<<

D:\power>

我报上面的错误。

TOP

回复 10# xczxczxcz

哪里有好用的powershell,手上的版本好像被微软禁用了。

TOP

回复 10# xczxczxcz

powershell -file 脚本.ps1
是这样运行吗?

刚弄了个Hello,World可以运行,

Write-Host "Hello World!"
Write-Host "lk"

把上面保存到脚本里面,powershell -file 脚本.ps1还是报错,不知道哪里不对?

TOP

回复 9# netdzb


哪一句? 偶测了下,一路OK。

TOP

回复 8# xczxczxcz

我装的是powershell V2版本,代码无法通过。

TOP

确保你的系统能正常使用 POWERSHELL ,否则PASS, 下面的脚本用 WINRAR 安装目录下的 RAR.EXE 非 WINRAR.EXE。偶已集成 RAR.EXE 到系统环境变量中,所以直接使用。至于 winrar.exe 和 rar.exe 是否有相同的用法和效果。未知。

确保 使用工作路径 切换到 你要操作的文件夹。
  1. $files =ls |?{$_.Directory};
  2. $Begin, $n =0,1;
  3. While ( $Begin -lt $files.Count )
  4. {
  5. $name =$n.ToString().PadLeft(3,'0')+'.rar';
  6. & rar a -ep $name $files[$Begin].FullName|Out-Null;
  7. if ((Get-Item $name).Length/1MB -gt 20) {
  8. & rar d -ep $name $files[$Begin].Name|Out-Null;
  9. $n++;
  10. } else { $Begin++ }
  11. }
复制代码

TOP

返回列表