7zip decrypt encrypted folder/file names - 7zip

I have been testing a little utility called CryptSync which uses 7zip to encrypt/compress a folder/file structure (then i can upload to a cloud drive the 7zipped separate files with nice encryped file and folder names).
The problem i have is that i would like a little batch file to decrypt the resulting encrypted folder names and 7zip files and am really struggling to work out how to decrypt the 7zip encrypted folder names
I have a rough working windows batch script here that works fine and decrypts all the individual 7zip files in all folders and subfolders .. but it still leaves the directory names encrypted.
Could anyone suggest any options to get the directories decrypted ... thx
here is my working script :
FOR /D /r %%F in ("*") DO (
pushd %CD%
cd %%F
FOR %%X in (*.7Z) DO (
"C:\Program Files\7-zip\7z.exe" x "%%X" -p"MYPASSWORD"
)
popd
)
as a second question if i may .. could anyone tell me how i get the script to delete the .7zip (and rename the old encrypted directory name) after succesfully extracting/decrypting

The files are stored in the 7z file without any path. The path encryption is done by CryptSync alone, not using 7z at all. That means there is no way for you to decrypt the path from one 7z file.

Related

How to batch copy files based on a list (txt) in to another folder with same directory structure?

I have a root directory with over 25,000 files in it. These files are in loads of different subdirectories.
I also have a text file with 4300 lines in it, each line is an absolute path to one of the files in the directory. Like below,
c:\dir1\hat1.gif
c:\dir1\hat2.gif
c:\dir1\dir2\hat1.gif
c:\dir1\dir2\hat2.gif
c:\dir1\dir3\cat.zip
c:\dir1\dir3\banana.exe
I also have another root directory witch is a copy of the original root directory structure but all the directories are empty.
I would like to copy all the files listed in the text file to the directory which is empty and place all the copied files inn the respected subdirectories.
if I use the following batchfile I keep getting file overwrite prompts because it is not copying the files to the correct directories.
#echo off
set dst_folder=c:\DSTN2
for /f "tokens=*" %%i in (USEDFILES.txt) DO (
xcopy /S/E "%%i" "%dst_folder%"
)
How do I modify this so the files are copied to the correct directory?
Since you are copying specific files from a list, you need to make sure the directory structure exists in the destination if you want it in a similar folder structure. So using the power of the FOR command modifiers you can get the file path only from the file name in the file list. You will use that modifier to create the destination directory and also use it as the destination for the XCOPY command.
I have taken the liberty of providing best practices for all the code you are using.
#echo off
set "dst_folder=c:\DSTN2"
for /f "usebackq delims=" %%G in ("USEDFILES.txt") DO (
mkdir "%dst_folder%%%~pG" 2>NUL
xcopy "%%~G" "%dst_folder%%%~pG"
)

Batch OCR files in subfolders and save new files with new name

I have the following code, which OCR's all PDF files in a specific folder (d:\extracttmp2), but it does not rename the files as I would like, or put the new files in the right place.
Currently, all files are within subfolders of 'extracttmp2'.
The OCR runs correctly, but I would like the OCR'ed files to be renamed to: <parent folder path>-<filename>_ocred.pdf. Naming them in such a manner will produce no file overwrites.
Currently, the code OCR's the files, but it saves the new files to the folder above the folder they are located in. It also saves the filenames as "JAN_ocred.pdf", for example, for a file named "JAN.pdf". The result of saving up one folder leads to some file overwrites, which is unwanted.
Also, it doesn't matter if the OCR'ed files remain in the folder where the un-OCR'ed files are located, or if they're saved up one folder. The desired renaming will eliminate any overwrites.
The software I'm using is PDF24. https://creator.pdf24.org/manual/10/#command-line. However, I think that my problem is not with the OCR software, but my syntax in the batch script.
Can anyone tell me what I am doing wrong?
For /R d:\extracttmp2\ %%G in (*.pdf) do "C:\Program Files\PDF24\pdf24-Ocr.exe" -outputFile "%%~nG_ocred.pdf" -language eng -dpi 300 -skipFilesWithText "%%G"
Is this what you mean? i.e. files will be saved in the same location as before, but each name will be prefixed with their parent directories' name, followed by a hyphen/dash.
#For /R "D:\extracttmp2" %%G In (*.pdf) Do #For %%H In ("%%~dpG.") Do #"%ProgramFiles%\PDF24\pdf24-Ocr.exe" -outputFile "%%~nxH-%%~nG_ocred%%~xG" -language eng -dpi 300 -skipFilesWithText "%%G"
Just a quick clarification: D:\extracttmp2\directory1\JAN.pdf would be saved in the working directory with the name directory1-JAN_ocred.pdf, and D:\extracttmp2\directory2\subdirectory3\SOMENAME.pdf, as subdirectory3-SOMENAME_ocred.pdf
If you want to save the files somewhere else, either change the working directory, or prepend it to %%~nxH-%%~nG_ocred%%~xG

How to copy a file from a USB drive to C drive in Windows 10 using a batch file?

I have some files in a USB drive which need to be copied to multiple computers. These files contain an executable which will use the other config files.
My issue is, for Windows 10 PCs, while the temp_folder gets created, none of the files get copied.
For windows 7 I was able to create a batch file which copied the files to the local drive and ran the executable using the config files.
The batch file contents were as below :
mkdir C:\temp_installer
copy ".\file_name" "C:\temp_installer"
<rest of the code>
I have tried using xcopy and robocopy, but still see the batch file run and just stop at creating the folder. The same issue isn't observed in Windows 7.
Has someone tried this or can someone tell me what I might be doing wrong?
This would be a better option, we do not need to be concerened about permission issues on the root of C:
#echo off
cd /d "%~dp0"
set "inst_dir=%temp%\temp_installer"
mkdir "%inst_dir%">nul 2>&1
for %%i in (*) do if not "%%i"=="%~nx0" copy /Y "%%i "%inst_dir%"
:# When completed, we can call execute the files from "%inst_dir%"
The for loop is not needed to be honest, I am only doing it to not copy the .bat/.cmd file itself to the folder as there would be no need for it there.
Or even simpler, without having to do all the above, you could just use robocopy
#echo off
cd /d "%~dp0"
robocopy /MIR .\ "%temp%\temp_installer"
Powershell is your friend here, try this:
Copy-Item E:\Document\ C:\Temp\Document\ -R
Works great for me and it even creates destination directory, also Copy-Item has alias cp and copy.
If you running some sort of script, you might have issues with Execution-Policy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

CMD/BATCH From folders in current location

I believe it should an easy way of doing this, but I could not figure out how.
Current situation:
Customer send zip file to our SFTP folder, by using some easy batch files it copy zip files from SFTP, unzip it and carry on with the rest of the things which has to be done.
What I need:
Inside zip file there is a folder(main problem that it could be named randomly). All what I need is a BATCH file which will copy all files from any existing folders in current(job) location.
Edit:
Current method is a really bad(but it solid and working), I just simply change the name of the folder in batch file and everything run nice and smooth. Method is working fine, but I would like to automate it completely.
You can iterate over the directories in the extracted archive directory using DIR /A:D which only gets directories. This will process more than one subdirectory if it is found.
SETLOCAL ENABLEDELAYEDEXPANSION
SET "EXTRACTED_DIR=C:\path\to\extracted\archive"
FOR /F "usebackq tokens=*" %%d IN (`DIR /A:D /B "%EXTRACTED_DIR%"`) DO (
SET "THE_DIR=%%~d"
ECHO Do something with mystery directory "%EXTRACTED_DIR%\!THE_DIR!"
)

How to delete file only if subdirectory with same name exists in Windows

Usually I extract .zip and .rar files in a directory maned as the file without the extension.
E.g.:
test.zip
test\
Now I'd like to write a Windows batch script that browses all hard drive to delete all .zip or .rar files whenever in the same directory is present a subdirectory with same name of the file without the extension.
But I really don't know where to start.
Thank you in advance.
This simple script is all you need to delete all zip files within C: drive appropriately.
#for /r c:\ %%F in (*.zip) do if exist "%%~dpnF\*" del "%%F"
You don't even need the script. You can simply run the following from the command line:
for /r c:\ %F in (*.zip) do if exist "%~dpnF\*" del "%F"

Resources