批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖
回复  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

回复 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

回复 15# xczxczxcz

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

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

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

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

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

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

TOP

回复 19# netdzb


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

TOP

回复 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

回复 22# netdzb

把  PS 脚本的第一行改成 $files =ls -rec|?{$_.Directory};
其它不变,看能不能满足你的要求。如果要保存原来文件的目录结构,自行删除 -EP 参数。

TOP

回复 23# xczxczxcz

测试了,还是没有文件夹。

TOP

回复 24# netdzb


    是把文件夹内的文件一起提出来了,不建立文件夹。

TOP

回复 25# xczxczxcz

把ep去掉就文件夹了。

TOP

你自己根据需要 修改 RAR 参数吧。偶们也不明白你的最终需求。

TOP

回复 22# netdzb


试试这样可以比较文件大小吗:
  1. @echo on
  2. setlocal enabledelayedexpansion
  3. set num=100
  4. for /f "delims=" %%i in ('dir /a-d /b /s *.*') do (
  5.     rar a I:\hand\temp.rar "%%i"
  6.     for %%a in ("I:\hand\temp.rar") do (
  7.         if %%~za leq 20971520 (
  8.             echo %%a 不大于20MB
  9.             REM 把你需要的操作放在这里
  10.         )
  11.     )
  12.     copy /y I:\hand\temp.rar I:\hand\!num:~-2!.rar
  13.     set /a num+=1
  14.     del /f I:\hand\temp.rar
  15. )
  16. pause
复制代码
【扫描二维码捐助论坛的朋友请留言注明论坛账号】http://bbs.bathome.net/thread-10403-1-1.html
【批处理在线视频分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

TOP

回复 28# Batcher

代码有错误,会在页面显示代码,好像是多了括号。

TOP

回复 29# netdzb


    echo on 改成 echo off 试试呢?如果还是不行,请把报错信息发出来看看。我数了一下,5个左括号、5个右括号,没发现多或少。
【扫描二维码捐助论坛的朋友请留言注明论坛账号】http://bbs.bathome.net/thread-10403-1-1.html
【批处理在线视频分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

TOP

返回列表