I have one zip file in source path called crewing.zip, zip file structure is as follows:
crewing\Build\Areas
i just want to extract only the folders and files under Build, i dont want the parent folder Build to be in destination location
Source Folder path: \10.201.1.6\TempPath\CL1
Destination Folder path: D:\Client1\inetpub\wwwroot
Expected Result: D:\Client1\inetpub\wwwroot\crewing\Areas
in unzip format, below is the code which i tried in batch files
7za X \10.201.1.6\TempPath\CL1\crewing.zip -y -oD:\Client1\inetpub\wwwroot crewing\Build* -r
please help me now in destination parent folder build also obtained.
Try:
7z x -y -oD:\GWClient\inetpub\wwwroot \10.201.1.6\MariApps\GW\crewing.zip crewing\Build\*
You'll have to remove the Build dir afterwards.
Related
I would like to convert a large number of html files to txt files. I have downloaded the inscript command line tool from github but I am struggling to apply it to all html files which are located in subdirectories and then save these files as text files in the same directory where the html files are located.
I have tried:
for f in ./ do inscript.py -o test.txt done
The following should work:
for d in ./**/*/; do
pushd "$d"
for f in *.html(N); do
out=test-${f%.html}.txt
inscript.py -o "$out" "$f"
done
popd
done
The pattern .**/*/ will recursively match the current directory and all its subdirectories. pushd will change to a directory, but remember the current working directory. inscript.py does its thing, then popd returns to the original working directory so that the next value of d continues to be a valid
relative directory.
Changing the working directory isn't strictly necessary; it just simplifies the file paths involved, because you focus on the name of the file and ignore the rest of the path.
I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.
I own a MacBook Air. I'm trying to unzip all of these folders all at once instead of double clicking on each zip file that are in each directory. Is it possible? If so, how? For example, Folder 1 contains Cow.zip and Pig.zip, Folder 2 contains Dragon.zip, Dog.zip, and Cat.zip and
Folder 3 contains Hen.zip and Flowers.zip. Folder 1, Folder 2, and Folder 3, are in File called Animals.
Try this:
open ./*/*.zip
This will recursively traverse all the folders in the current directory and open all .zip files (i.e. "double click"/unzip).
If you need to unzip lots of files, use this command instead to avoid numerous pop ups. (Replace path/to/folder with the path that contains the folders with zips/more folders)
find path/to/folder -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename"`" "$filename"; done;
I have files at location D:\data\Generate which needs to be Zipped and copied to
D:\data\Upload directory
I used command
set generate=D:\Data\Generate
set upload=D:\Data\Upload
cd %generate%
zip - * >> %upload%\%%i.zip
If I run this command from cmd it works fine but while running it from a
scheduler (ex: Control-M) it actually copies all the files from Control-m config directory into the zip folder.
If I explicitly mention the directory under whose the files needs to be zipped
zip - %generate%*.* >> %upload%\%%i.zip
the final zip folder actually contains the whole directory structure too instead of just the files.
ex: Zip file contains Data folder, Generate folder and the files under Generate folder
Can someone please help with this?
ok I got some clue with this.
This is a problem with Windows itself, for ex:
You open CMD
You are currently in directory C
then you run a command cd D:\data
even after this when you do dir, it will list out all the jobs in C directory only.
if you run D: after the above CD it will actually go into D:\data directory and you can work on that directory
I am sure you are past this since two (2) years ago. Here is a way to do it. I did not understand what you wanted the .zip archive filename to be. There is nothing in the source code presented that would produce %%i.
powershell -NoProfile -Command "Get-ChildItem -File -Path 'D:\Data\Generate' | Compress-Archive -DestinationPath 'D:\data\Upload\i.zip'"
I need to move a bunch of files in the /data/files directory to a new folder structure. In the /data directory, I have a manifest file that contains the full working path of each file.
Source Files:
/data/files/this_file_1.sh
/data/files/this_file_2.sh
Manifest File Contains:
/path/to/where/file/goes/this_file_1.sh
/a/different/path/to/file/this_file_2.sh
I need help writing a shell script that will find the filename in the manifest and run a copy command. If the directory structure doesn't exist, create it.
#!/bin/bash
for file_name in $(cat manifest); do
name=$(basename $file_name);
path= ??
# Mkdir / Copy
done
How can I get the filename from the full path of the file?
How can I create the directories prior to copying the files?
I'm going to let you write the full script, but here are some commands you could use:
"Find the filename in the manifest" - basename filepath
"Verify it exists in /data/files" - if [ -e filename ]; then ......
"Run a copy command" - cp location1 location2
"If the directory structure doesn't exist, create it" - else mkdir /data/files or whatever the directory you want to create is.
If you have any questions about these commands leave a comment :-)