How do I exclude a subfolder of a subfolder in compress-archive - powershell

I want to zip a folder containing files, and subfolders containing more files and more subfolders. But I want exclude just one subfolder of a subfolder. I have seen many various complicated answers but none seem to really work on this scenario.
folder structure
temp/
a/
aa/
aaa/
aaaa/
filesinaaaa.txt
filesinaaa.txt
filesinaa.txt
at.txt
b/
bb/
bt.txt
c.txt
I want to exclude all files in a/aa/aaa/ while keeping the resulting zip in the same dir structure. And if possible remove the files that were included in the zip.
So result expected is
temp/
a/
aa/
aaa/
aaaa/
filesinaaaa.txt
filesinaaa.txt
result.zip
In linux it is as simple as
cd temp
zip -rm result.zip . -x "a/aa/aaa/*"
what is the simplest way to do this in powershell?
answers i've tried do not really work on subfolder of a subfolder.
Exclude sub-directories from Compress-Archive Powershell Cmd
How do I exclude a folder in compress-archive
over complicated result
Archive folder without some subfolders and files using PowerShell

You can use 7z CLI to do so, here is the doc explaining the usage of -x option in 7z
Showing an example of the option below for reference
The directory structure explained in the question:
C:\Users\adam_\Desktop\temp〉dir -R
a b c.txt
./a:
aa at.txt
./a/aa:
aaa filesinaa.txt
./a/aa/aaa:
aaaa filesinaaa.txt
./a/aa/aaa/aaaa:
filesinaaaa.txt
./b:
bb bt.txt
./b/bb:
Creating the archive:
PS C:\Users\adam_\Desktop\temp> 7z a -tzip result.zip . -x!a/aa/aaa/*
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
5 folders, 4 files, 63 bytes (1 KiB)
Creating archive: result.zip
Add new data to archive: 5 folders, 4 files, 63 bytes (1 KiB)
Files read from disk: 4
Archive size: 1217 bytes (2 KiB)
Everything is Ok
Result archive details:
PS C:\Users\adam_\Desktop\temp> 7z l .\result.zip
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive for archives:
1 file, 1217 bytes (2 KiB)
Listing archive: .\result.zip
--
Path = .\result.zip
Type = zip
Physical Size = 1217
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2022-05-05 09:48:37 D.... 0 0 a
2022-05-05 09:48:12 D.... 0 0 a\aa
2022-05-05 09:47:45 D.... 0 0 a\aa\aaa
2022-05-05 09:48:12 ....A 13 13 a\aa\filesinaa.txt
2022-05-05 09:48:37 ....A 13 13 a\at.txt
2022-05-05 09:49:20 D.... 0 0 b
2022-05-05 09:48:58 D.... 0 0 b\bb
2022-05-05 09:49:20 ....A 19 19 b\bt.txt
2022-05-05 09:49:56 ....A 18 18 c.txt
------------------- ----- ------------ ------------ ------------------------
2022-05-05 09:49:56 63 63 4 files, 5 folders

Related

rsync tries to copy although file is copied

I'm trying to understand the following, maybe one of you guys can help me out by explaining on what exactly happens here:
My goal is to write a script, which copies files from the find-command, parallels rsync-commands and backup those, by re-creating the folder-structure from the source on the destination as well.
Somehow my initial script does not work like that, and i don't really have an idea on how to fix it to behave that way.
Initially, i've copied the files with "ls -1 /foldername" as sourceFolder, which is not best-practice. So i've tried to change it to using "find" as described beyond.
find "$sourceFolder" -maxdepth 2 -mindepth 2 -print0 | xargs --verbose -0 -I {} -P $maxThreads -n 1 rsync -valhP {}/ "$destFolder"/ --checksum --human-readable --stats --dry-run >> "$logDir"/result.log
--
If i run this script, it literaly would recopy the file(s), although those exist in the destination folder i would expect it to be.
sending incremental file list
.d..tp..... ./
>f+++++++++ macs.txt
Number of files: 2 (reg: 1, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 0
Number of regular files transferred: 1
Total file size: 242 bytes
Total transferred file size: 242 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.484 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 83
Total bytes received: 22
So as it turned out, sourceFolder and destFolder have to match, and i can't run anything like sourceFolder/folder1/folder1a destFolder/.
Can anyone help me out on what's wrong and why it behaves like that?
Thanks a Lot,
M.

Powershell script to search folder delete them create a log file of it with specific data

Need to create a PowerShell script which does browses through folders E:\user, E:\Employee, E:\admin.
If in this folder there are folders starting with CIN Or PIN and length 6 (eg:CIN123) , delete subfolders 'log' and 'Data'. eg E:\user\cinpp123\log.
Create a log file of this in E:\logfile\
ex 2020-02-18 02:00 folder successfully deleted E:\logfile\cinpp123\log 350 MB
2020-02-18 02:00 failed deleted E:\logfile\cinpp123\Data 350 MB

Why Does Robocopy Skip A File During Builds?

I added a robocopy file to my post build event in my C# project. X64 Release and Debug build fine, as does X86 Debug, however the X86 Release option does NOT copy the Get-Parent-Device.exe file to the target.
Why?
Note: I can always just add a step and copy over the file manually just for that specific configuration and that would "solve" my problem, however I want to understand what issue robocopy had. The source and destination are fine, permissions are fine, just X86/Release does not work.
What is interesting is that if I right click on the solution and select build, robocopy works on that configuration. What does not work is if I use Visual Build Professional and build all configurations of the project.
Here is the log+ file:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Tuesday, September 25, 2018 10:16:57 AM
Source : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\
Dest : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x86\Release\
Files : Get-Parent-Device.exe
Options : /V /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
0 C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Tuesday, September 25, 2018 10:16:57 AM
Here are the relevant steps from the post build event:
robocopy /V /IS /log+:"$(TargetDir)robo.log" "$(ProjectDir)..\Get-Parent-Device\Release" $(TargetDir) Get-Parent-Device.exe
robocopy "$(ProjectDir)..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\$(PlatformName)" $(TargetDir) SQLite.Interop.dll
exit 0
Here is a screenshot of the build steps.
I saw the recommendation to use /MIR, but I do not want to mirror, just copy that specific file. Sadly, /log, /log+, and /v do not provide very verbose information on why in this specific instance, robocopy felt the need to not copy over the file.
I do not like to sweep the problem under the rug or to to understand a technical problem, hence my post here. My concern is that if I cannot rely on Robocopy, then it might be a bad choice for use inside Visual Studio. I need a reliable copy, not an unreliable one.
XCOPY TRIAL:
That did not work. So far the best solution is still a Visual Build Pro instruction for that specific configuration. :-(
PostBuildEvent:
"C:\Program Files\Editors\VisBuildPro9\Tools\signtool.exe" sign /f "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\jmrDigicert-2017-NoChain.pfx" /p 1234 /t http://timestamp.verisign.com/scripts/timstamp.dll "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe"
xcopy /i "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\
robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\x64" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ SQLite.Interop.dll
robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\..\Redistributables" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ AMBackup.exe
exit 0
Done Adding Additional Store
Successfully signed and timestamped: C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe
C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe
1 File(s) copied
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Robocopy is designed to only copy changed files, but the option /IS you have added is suppose to copy whatever you like. Try to add parameter /IT (Includes "tweaked" files), but in my experience it is not reliable either.
This post How do I force Robocopy to overwrite files? confirm my findings. Their solution was same as mine: use XCOPY.
This https://superuser.com/questions/314503/what-does-robocopy-mean-by-tweaked-lonely-and-extra/445137#445137 table shows how robocopy groups files.
Edit:
The error message you get is typically that "file does not exists" in source.Since your XCOPY test also failed then I'm 100% sure that the file does not exists.
Se example below:
C:\>dir x
Volume in drive C has no label.
Volume Serial Number is CE46-5CC1
Directory of C:\x
25.09.2018 23:37 <DIR> .
25.09.2018 23:37 <DIR> ..
27.07.2016 15:09 1 209 somefile
1 File(s) 1 209 bytes
2 Dir(s) 125 137 285 120 bytes free
C:\>robocopy /IS x y somefile
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:07
Source : C:\x\
Dest : C:\y\
Files : somefile
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\x\
100% New File 1209 somefile
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 1.1 k 1.1 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 1209000 Bytes/sec.
Speed : 69.179 MegaBytes/min.
Ended : tirsdag 25. september 2018 23:38:07
C:\>robocopy /IS x y somefile
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:13
Source : C:\x\
Dest : C:\y\
Files : somefile
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\x\
100% Same 1209 somefile
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 1.1 k 1.1 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 1209000 Bytes/sec.
Speed : 69.179 MegaBytes/min.
Ended : tirsdag 25. september 2018 23:38:13
C:\>robocopy /IS x y somefilex
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:17
Source : C:\x\
Dest : C:\y\
Files : somefilex
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
0 C:\x\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : tirsdag 25. september 2018 23:38:17
C:\>
I have encountered simular problems when building in Visual Studio. But I had to change the Build Dependencies and build order to solve it.
You could try to add a small delay in the post build, try adding like:
ping 127.0.0.1 -n 3 > nul
It will pause for 2 seconds before it continues...

Get Jar/Java from INSTALL4J .exe

Hi Im new to install4j so forgive my misunderstandings, I have a x64 .exe that was built using INSTALL4J is there any way to get the java/jar out of it? does everything get compiled to PE64? This is the 7zip list of the .exe archive:
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2014-12-03 16:37:21 ..... 173056 173056 .text
2014-12-03 16:37:21 ..... 40960 40960 .rdata
2014-12-03 16:37:21 ..... 9216 9216 .data
2014-12-03 16:37:21 ..... 7680 7680 .pdata
..... 1612 1612 .rsrc\0\version.txt
..... 302 302 .rsrc\1033\DIALOG\101
..... 1188 1188 .rsrc\0\MANIFEST\1
2014-12-03 16:37:21 ..... 2048 2048 .reloc
2014-12-03 16:37:21 ..... 7384 7384 CERTIFICATE
2014-12-03 16:37:21 ..... 3072 3072 [0]
------------------- ----- ------------ ------------ ------------------------
2014-12-03 16:37:21 246518 246518 10 files
There is no PK value as per here
And another thing how do you debug such an .exe windbg can makes sense of it and a java debugger cannot see the process?
Launchers generated by install4j do not contain the JAR files, they use JNI to create the JVM and they include external JAR files into the classpath. You can run the launcher with the /create-i4j-log argument to see what it is doing.

Creating an eclipse plugin without gui: what am I missing?

I'm creating an eclipse plugin using java code generated via a Makefile (yes, I know ant). The final target of my makefile is a zip containing the following structure (I used the plugin for javacc as an inspiration):
$ unzip -l myplugin_2015.02.16.zip
Archive: myplugin_2015.02.16.zip
Length Date Time Name
--------- ---------- ----- ----
0 02-16-2015 09:30 feature/
0 02-16-2015 09:30 feature/myplugin.feature_2015.02.16/
474 02-16-2015 09:30 feature/myplugin.feature_2015.02.16/feature.xml
0 02-16-2015 09:30 plugins/
0 02-16-2015 09:30 plugins/myplugin_2015.02.16/
0 02-16-2015 09:30 plugins/myplugin_2015.02.16/META-INF/
527 02-16-2015 09:30 plugins/myplugin_2015.02.16/META-INF/MANIFEST.MF
492 02-16-2015 09:30 plugins/myplugin_2015.02.16/plugin.xml
23079 02-16-2015 09:30 plugins/myplugin_2015.02.16/idp192.jar
--------- -------
24572 9 files
No I'd like to import this zip in eclipse as a new plugin. When I run eclipse->install-new-software->Add->archive it fails with "no software size found for jar:... , do you wish do edit location ?".
I suspect I need to wrap this zip in a site file ? is there a minimal way to create this 'site' archive ? or is there a simplier solution , something missing in my plugin.zip ? Most important, I don't want to use any GUI.
Thank you for your help
fixed a few hours later: just moving my *.jar to eclipse/plugin fixed the problem.