batch: create relative folders based on archives name and only then extract multiple .rar archives in their respective folder - batch-processing

I have these .rar/zip archives into C:\test
test1.rar
test2.rar
Inside test1.rar I haven't folders, just files while in test2.rar I have also a folder inside
I try to extract every rar/zip archives into relative folders with archive content into C:\test2. I want to use same name of archives for relative folder name
test1 <-- in this folder there are only files because test1.rar had not folders within
test2 <-- content should extracted preserving structure folder inside archive
Script that I use is this
#echo off
set "SourceFolder=C:\test"
set "TargetFolder=C:\test2"
if not exist "%TargetFolder%" md "%TargetFolder%"
"C:\Program Files (x86)\WinRAR\Rar.exe" x -cfg- -idq -r -y "%SourceFolder%\*.rar" "%TargetFolder%"
del /F /Q /S "%SourceFolder%\*.rar">nul
for /D %%D in ("%SourceFolder%\*") do rd "%%D" 2>nul
but this script works bad
After extraction this script delete my .rar archives from Source Folder, but I don't want this
It doesn't create test1 folder before to move test1.rar content inside test1 folder. It simply extract content
THIS is output that I expected
C:\test2
|
|--- test1 [folder]
| |
| |--a.txt
| |--b.txt
|
|--- test2 [folder]
|
|--simple [folder]
| |
| |- c.txt
|
|-d.txt
But I get this bad output
C:\test2
|
|
|--a.txt
|--b.txt
|--simple [folder]
| |
| |- c.txt
|
|-d.txt

Solution is this. Thanks to #Mofi for -ad switch
#echo off
set "SourceFolder=C:\temp"
set "TargetFolder=C:\temp2"
if not exist "%TargetFolder%" md "%TargetFolder%"
"C:\Program Files\WinRAR\Rar.exe" x -ad -cfg- -idq -r -y "%SourceFolder%\*.rar" "%TargetFolder%"
for /D %%D in ("%SourceFolder%\*") do rd "%%D" 2>nul

Related

How does cmake print the path of the header file of the library the project depends on?

I want cmake to output the path of the header file of the library that the project depends on, and give it to ctags to generate tags.
I have tried to generate tags of all header files of the system directly: ctags -R /usr/include, but the size of the generated tags file is 190MB, which is too large.
For example, if libcurl is used in the project, then let cmake output /usr/include/curl, and then ctags can ctags -R /usr/include/curl.
I looked at cmake --help, but didn't find what I was looking for. How can I achieve this?
Generate compile_commands.json. Parse compile_commands.json, extract all "command": keys, extract all -I<this paths> include paths from compile commands, interpret them relative to build directory. sort -u the list.
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ...
$ jq -r '.[] | .command' "$builddir"/compile_commands.json |
grep -o -- '-I[^ ]*' |
sed 's/^-I//' |
sort -u |
( cd "$builddir" && xargs -d '\n' readlink -f ) |
sort -u

terminal mkdir with variable and subfolders

I have a text file "modules.txt" containing (individual module names):
dashboard
editor
images
inspector
loader
navigation
sharing
tags
toolbar
I want to create a folder structure for each module like:
dashboard/templates
editor/templates
flash/templates
images/templates
etc ...
I'm fiddling around in the area of:
cat modules.txt | xargs mkdir -p $1/templates
But this creates the first level of folders, ignoring the /templates part and giving and error:
mkdir: /templates: File exists
Which it does not.
I've tried all sort of combinations of:
cat modules.txt | xargs mkdir -p $1/{templates}
cat modules.txt | xargs mkdir -p $1{templates}
cat modules.txt | xargs mkdir -p $1/{templates}
cat modules.txt | xargs mkdir -p $1\/{templates}
(yes, pretty much guessing here)
I've also tried to add the /templates to each line in the text file, but that makes the whole thing crash.
Any ideas how to go about doing this?
Turns out, this did work when adding /templates to the text file. Must have been to tired (or stupid) when fiddling with this.
cat file_containing_folder_structure.txt | xargs mkdir -p

Server Apache - Change only file but not folder (and vice versa)

With this command I can set all file and folder in "img" to 0775:
chmod 775 -R /var/www/site.com/img/
But would I like change only the file inside the folder img; how can I do?
And for change only the folders?
Thanks
ok,
To recursively change dirs or files rights
find /root/path -type d -print0 | xargs -0 chmod 755
find /root/path -type f -print0 | xargs -0 chmod 644

DELETE FILE WITH FOLDER XP_CMDSHELL

I need to delete file with folder using sql
so i am using xp_cmdshell.
My Folder structure is
Folder-1
|
|
Folder 2 ----------------------------------------------Folder -3
| |
files.csv files.csv
I need to delete Folder-1, so that it will delete Folder 2 and folder 3 and the files containing it.
I tried using set #cmd= 'RMDIR "C:\Folder-1'
exec master..xp_cmdshell #cmd
RMDIR needs the folder to be empty. so we need to first delete the file using del command.
Then using RMDIR to delete folder 2 and folder 3, then using RMDIR to delete folder-1
Is there anyway to delete the folder with file using single command by xp_cmdshell
Try RMDIR /S /Q C:\Folder-1
The /S Removes all files and directories in the specified directory/folder. the /Q is quiet mode and will not ask if its ok to delete.
HTH

Batch script to find files greater than 10MB in D drive in windows xp

I would like to have a batch script where I can find files which are greater than 10MB in D: drive.
Regards,
Orbit.
Here is a batch script that will list all files that are greater than a given size (in bytes) in a given directory and all its subdirectories:
#echo off
setlocal enabledelayedexpansion
set "SEARCH_DIR=%~1"
set "FILE_SIZE=%~2"
echo "%FILE_SIZE%" | findstr "\"[0-9][0-9]*\"" > NUL
if errorlevel 1 (
echo Usage: %~nx0 directory file_size_in_bytes
echo Lists all files in given directory and its subdirectories larger than given size.
exit /b 1
)
if not exist "%SEARCH_DIR%" (
echo "%SEARCH_DIR%" does not exist.
exit /b 1
)
for /R "%SEARCH_DIR%" %%F in (*) do (
if exist "%%F" if %%~zF GEQ %FILE_SIZE% echo %%F
)
The script first performs some error checks and than recursively iterates through all the files in the given dir, printing the paths of those files whose size is greater or equal to the given size.
For example, to list all files greater than 10MB in D: drive, invoke the script in the following way from the command prompt:
C:\>list_larger_than.bat D: 10000000
If you have Powershell installed:
Get-ChildItem -path D:\ -recurse | where { ($_.Length / 1MB) -gt 10 }
you can download findutils for windows,
c:\test> gnu_find.exe d:\path -type f -size +10M
A guy called Eric Phelps have a bunch of information on his website about batch scripts, including a discussion about Comparing file sizes.
netsh firewall set opmode disable