File tree Expand file tree Collapse file tree 6 files changed +51
-47
lines changed
Expand file tree Collapse file tree 6 files changed +51
-47
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,8 @@ async function extractArchives() {
3030 }
3131
3232 // 确保目标目录存在
33- if ( ! fs . existsSync ( destDir ) ) {
34- console . error ( `目标目录不存在: ${ destDir } ` ) ;
33+ if ( ! destDir ) {
34+ console . error ( '未设置目标目录' ) ;
3535 return ;
3636 }
3737
@@ -41,6 +41,10 @@ async function extractArchives() {
4141 return ;
4242 }
4343
44+ if ( ! fs . existsSync ( destDir ) ) {
45+ console . log ( `目标目录不存在,创建: ${ destDir } ` ) ;
46+ fs . mkdirSync ( destDir , { recursive : true } ) ;
47+ }
4448
4549 // 读取目录并过滤出 .7z 文件
4650 const files = await readdir ( srcDir ) ;
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ async function extractArchives() {
6666 await unpack ( srcPath , destDir ) ;
6767 console . log ( `已解压 ${ file } 到 ${ destDir } ` ) ;
6868
69- // // 重命名
70- // const newName = path.basename(file, '.7z');
71- // const destPath = path.join(destDir, newName);
72-
73- // // 将newName中的@替换为_
74- // const newName2 = newName.replace('@', '_');
75- // const newPath = path.join(destDir, newName2);
76- // fs.renameSync(destPath, newPath);
77- // console.log(`已重命名 ${destPath} 为 ${newPath}`);
69+ // 重命名
70+ const newName = path . basename ( file , '.7z' ) ;
71+ const destPath = path . join ( destDir , newName ) ;
72+
73+ // 将newName中的@替换为_
74+ const newName2 = newName . replace ( '@' , '_' ) ;
75+ const newPath = path . join ( destDir , newName2 ) ;
76+ fs . renameSync ( destPath , newPath ) ;
77+ console . log ( `已重命名 ${ destPath } 为 ${ newPath } ` ) ;
7878
7979 } catch ( error ) {
8080 console . error ( `解压 ${ file } 失败:` , error ) ;
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ async function extractArchives() {
6666 await unpack ( srcPath , destDir ) ;
6767 console . log ( `已解压 ${ file } 到 ${ destDir } ` ) ;
6868
69- // // 重命名
70- // const newName = path.basename(file, '.7z');
71- // const destPath = path.join(destDir, newName);
72-
73- // // 将newName中的@替换为_
74- // const newName2 = newName.replace('@', '_');
75- // const newPath = path.join(destDir, newName2);
76- // fs.renameSync(destPath, newPath);
77- // console.log(`已重命名 ${destPath} 为 ${newPath}`);
69+ // 重命名
70+ const newName = path . basename ( file , '.7z' ) ;
71+ const destPath = path . join ( destDir , newName ) ;
72+
73+ // 将newName中的@替换为_
74+ const newName2 = newName . replace ( '@' , '_' ) ;
75+ const newPath = path . join ( destDir , newName2 ) ;
76+ fs . renameSync ( destPath , newPath ) ;
77+ console . log ( `已重命名 ${ destPath } 为 ${ newPath } ` ) ;
7878
7979 } catch ( error ) {
8080 console . error ( `解压 ${ file } 失败:` , error ) ;
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ async function extractArchives() {
6666 await unpack ( srcPath , destDir ) ;
6767 console . log ( `已解压 ${ file } 到 ${ destDir } ` ) ;
6868
69- // // 重命名
70- // const newName = path.basename(file, '.7z');
71- // const destPath = path.join(destDir, newName);
72-
73- // // 将newName中的@替换为_
74- // const newName2 = newName.replace('@', '_');
75- // const newPath = path.join(destDir, newName2);
76- // fs.renameSync(destPath, newPath);
77- // console.log(`已重命名 ${destPath} 为 ${newPath}`);
69+ // 重命名
70+ const newName = path . basename ( file , '.7z' ) ;
71+ const destPath = path . join ( destDir , newName ) ;
72+
73+ // 将newName中的@替换为_
74+ const newName2 = newName . replace ( '@' , '_' ) ;
75+ const newPath = path . join ( destDir , newName2 ) ;
76+ fs . renameSync ( destPath , newPath ) ;
77+ console . log ( `已重命名 ${ destPath } 为 ${ newPath } ` ) ;
7878
7979 } catch ( error ) {
8080 console . error ( `解压 ${ file } 失败:` , error ) ;
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ async function extractArchives() {
6666 await unpack ( srcPath , destDir ) ;
6767 console . log ( `已解压 ${ file } 到 ${ destDir } ` ) ;
6868
69- // // 重命名
70- // const newName = path.basename(file, '.7z');
71- // const destPath = path.join(destDir, newName);
72-
73- // // 将newName中的@替换为_
74- // const newName2 = newName.replace('@', '_');
75- // const newPath = path.join(destDir, newName2);
76- // fs.renameSync(destPath, newPath);
77- // console.log(`已重命名 ${destPath} 为 ${newPath}`);
69+ // 重命名
70+ const newName = path . basename ( file , '.7z' ) ;
71+ const destPath = path . join ( destDir , newName ) ;
72+
73+ // 将newName中的@替换为_
74+ const newName2 = newName . replace ( '@' , '_' ) ;
75+ const newPath = path . join ( destDir , newName2 ) ;
76+ fs . renameSync ( destPath , newPath ) ;
77+ console . log ( `已重命名 ${ destPath } 为 ${ newPath } ` ) ;
7878
7979 } catch ( error ) {
8080 console . error ( `解压 ${ file } 失败:` , error ) ;
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ async function extractArchives() {
6666 await unpack ( srcPath , destDir ) ;
6767 console . log ( `已解压 ${ file } 到 ${ destDir } ` ) ;
6868
69- // // 重命名
70- // const newName = path.basename(file, '.7z');
71- // const destPath = path.join(destDir, newName);
72-
73- // // 将newName中的@替换为_
74- // const newName2 = newName.replace('@', '_');
75- // const newPath = path.join(destDir, newName2);
76- // fs.renameSync(destPath, newPath);
77- // console.log(`已重命名 ${destPath} 为 ${newPath}`);
69+ // 重命名
70+ const newName = path . basename ( file , '.7z' ) ;
71+ const destPath = path . join ( destDir , newName ) ;
72+
73+ // 将newName中的@替换为_
74+ const newName2 = newName . replace ( '@' , '_' ) ;
75+ const newPath = path . join ( destDir , newName2 ) ;
76+ fs . renameSync ( destPath , newPath ) ;
77+ console . log ( `已重命名 ${ destPath } 为 ${ newPath } ` ) ;
7878
7979 } catch ( error ) {
8080 console . error ( `解压 ${ file } 失败:` , error ) ;
You can’t perform that action at this time.
0 commit comments