Batch create subfolders inside parent folders, incorporating name of parent folder into the subfolder name - batch-processing

I've done my best to search for an answer to this but please forgive me if it exists as I'm a little new to this.
I'm trying to batch-create subfolders inside parent folders, incorporating the name of parent folder into the subfolder names. I'm using Windows 7.
So, I have a parent folder, Candybars
Inside the Candybars folder are hundreds of subfolders in the following format:
Candybars\firstword secondword possiblethirdword occasionalfourthword
Note that the subfolder names have spaces between the words. Some have just two words, (eg kitkat swiss) and some have three (eg kitkat swiss yummy) or occasionally four.
I'd like to put a subfolder in each of the existing subfolders, using the full name of the parent as part of the name of the subfolder, eg:
Candybars\firstword secondword\firstword secondword illustrations
So I might end up with something like:
Candybars\chocolate\chocolate illustrations
Candybars\kitkat swiss\kitkat swiss illustrations
Candybars\kitkat swiss yummy\kitkat swiss yummy illustrations
Candybars\special chocolate\special chocolate illustrations
Candybars\very special chocolate\very special chocolate illustrations
I would be monumentally grateful for any help with this. I'm going round in circles!
Thanks, Jon

You can do this with PowerShell. Create a file in the Candybars directory called, say, Subdirs.ps1 with contents:
Get-ChildItem |
where {$_.PsIsContainer} |
foreach {new-item -Name ($_.name + "\" + $_.name + " illustrations") -ItemType directory}
Then you can right-click on the file in Windows Explorer and select Run with PowerShell.

Related

How to copy my project folders and subfolders except contents (but PDF's must be included)

I'm a machine designer and I have a lots of project folders. I must copy my folders to public account, but public account area is limited. I must copy all folder structure include only pdf files. Other files must be except this. I.e. all folders and subfolders must be included and just pdf files.
If there is no pdf in that file, it should just copy the empty folder.
I can use only command prompt, I have no idea how I can with coding. Sorry for my English..
I tried search on google and I found this:
https://itigic.com/tr/use-xcopy-to-copy-a-folder-structure-in-windows/
"Xcopy" can be copy all folder structure but it can't copy pdf files.
I need only pdf files.
Xcopy, Copies files and directory trees.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J]
[/EXCLUDE:file1[+file2][+file3]...] [/COMPRESS]
It can seem daunting to a first-time user
" I must copy my folders to public account "
so first where in Public
Let us ASSUME "c:\users\PUBLIC\Public Documents" (WARNING note public is 2 times)
Make sure we will not destroy by overwrite other folders
WARNING Public Documents is a symbolic link thus that is NOT it's true folder name,
we must NOT have 2 Public, only 1 for xcopy, here I ask for a new folder called PDFs
Öte yandan /E, Xcopy'ye şunları da eklemesini söyler: alt klasörler tüm yapıyı kullanmak için boş olan, burada ilgilendiğimiz şey bu.
Navigate to the master folder you want to copy from
type cmd.exe in the address bar and press enter check cmd is showing that working folder>
and you want only all *.pdf and /E empty folders FROM THE CURRENT WORKING FOLDER. So from that working folder run xcopy, which should ask about the need for a new target.
xcopy *.pdf "c:\users\PUBLIC\DOCUMENTS\PDFs" /E
Does C:\users\PUBLIC\DOCUMENTS\PDFs specify a file name
or directory name on the target
(F = file, D = directory)? d
C:2022-11-16ExistingCustomerSRFINAL.pdf
C:2022-11-16NewBusinessSRFINAL.pdf
C:adobe_supplement_iso32000.pdf
....
many files and folders
...
C:tiff\TIFF6.pdf
C:tiff\TIFFphotoshop.pdf
C:tiff\TIFFPM6.pdf

How to add disk in zip using DotNetZip

I use DotNetZip for creating zips. It has many option but I couldn't find if it is possible to store the disk where the file is located, in the archive. E.g. like the Absolute mode in 7-Zip. As far as I can see I can only do this:
zip.AddFile(cFileFull, cPath);
When cFileFull is e.g. "c:\temp\SomeFile.txt" and cPath = "c:\temp" opening the zipfile shows
temp
while I would like to see
C
and then, when I click on C
temp
This allows storing the same path/file found on different drives. Is this possible?

Changing a string in an .exe file

I would like to know how to change a String in an .exe file. It is a list of 8 files which have all the same Content but are used in diferent paths. And These paths (Folders) are named 1-8. And now I have to Change that string ("word class 1") into 2-8 ("word class 2, ...") I did it manually with Notepad++ for a week now but it's time consuming and I don't want to do it anymore with Notepad++. :)
I don't mind any way of a solution to this Problem so, that's it.
I tried it with powershell so far but I can't figure out how to get the solution done with the get-content & select_string but it didn't work out as intended.
Thank you for reading and answering my question. (sorry for some typos)
You just want to replace some values within a .exe?
This is how I'd do it.
You need to provide a CSV file, first column titled OLD, second column titled new.
Here is my fake .exe file I made:
7deeadc7-a2b3-4c47-8cf6-61f09d986977ham
d1ea8982-4a04-4f2b-8e5a-244965921fccsam
b4a8f37a-c607-405b-8493-9b9b0e79673btam
0922496b-3064-4958-a6b0-46f61a711860turkey
e5f30554-e50e-4b61-aaa3-3797d9e0ed5ccheese
82e3d77f-53d5-49ef-bf84-b872dbbe556ffork
60a01cad-f6c4-44cc-af1a-fafb20377a12rice
e2cd71a1-7c34-456f-9af4-924f79874c38yummy
c85da055-c47e-41be-a0f8-5c320fa05317linux
7dbee5fc-87d5-4900-80c5-00818514d5b4morp
d9941dfe-dd97-422d-9088-2cecf4904fdepoo
05eaf9b3-09a2-45ea-b9a0-4c78ff9156f2pot
8c75d00d-4157-45b9-86df-74226790674fpoe
f0e77eb5-35fa-47f5-b89e-d1b5ef3c726fpoh
1d1ffc02-fee0-446d-aeac-940ab2864a76pof
Just a bunch of guids with a word at the end. Now, Here's my sample .csv file, with all of the replacements we want to make.
OLD,NEW
ham,pork
sam,Frodo
linux,Window
morp,porp
poo,restroom
Finally, here is the code to do this as a PowerShell Function.
Function Refresh-File {
param($inputCSV,$inputfile)
$file = get-content $inputfile
Foreach ($replacement in (Import-csv $inputCSV)){
$file = $file -replace $replacement.old,$replacement.New
}
$file | set-content $inputfile
}
Call it like this: Refresh-File -inputCSV T:\replace.csv -inputfile T:\blah.exe
Here's my .exe file after running this, just the value portions, to show you that it worked:
pork
Frodo
tam
turkey
cheese
fork
rice
yummy
Window
porp
restroom
pot
poe
poh
pof
Since you'll want to automate this, simply make a new replacement.csv file everyday. Then run this code. If you've never written a full PS1 script file before, as a quick summary, copy the function, paste it into notepad or the PowerShell ISE, and then at the last line of the script, put the command syntax to call the function. Save and enjoy.

Find all files of a given extension when a specific file type exists in another directory

Description
Using Powershell, I am trying to find a list of .vb files that exist in any folder, but only if the bin folder in that directory contains any .compiled file. I will be running this on 1 directory which will contain many folders. The trouble I am having is that the bin folder will not always be at the same depth in the folder structure. I have outlined this with sudo code and examples below. Be sure to see the final result at the very end of the post. Thanks!
Sudo Code
if any '*.compiled' file exists in d:/inetpub/[Unspecified_Number_of_directories]/x/bin
then Find all files recursively in d:/inetpub/[Unspecified_Number_of_directories]/x with extension '*.vb'
Examples
execute directory: d:/inetpub
example 1:
d:/inetpub/123/abc
/bin/
-code.dll
-morecode.dll
-lesscode.compiled
/folder1/
-compiledPage.aspx
-regularPage.aspx
-regularPage.aspx.vb
-anotherPage.aspx
-anotherPage.aspx.vb
/folder2/
-auth.vb
Should result:
d:/inetpub/123/abc/folder1/regularPage.aspx.vb
d:/inetpub/123/abc/folder1/anotherPage.aspx.vb
d:/inetpub/123/abc/folder2/auth.vb
example 2:
d:/inetpub/123/xyz
/bin/
-code.dll
-morecode.dll
-lesscode.dll
/folder1/
-compiledPage.aspx
-regularPage.aspx
-regularPage.aspx.vb
-anotherPage.aspx
-anotherPage.aspx.vb
/folder2/
-auth.vb
Should result:
Nothing
example 3:
d:/inetpub/456
/bin/
-less.compiled
/folder1/
-test.aspx
-test.aspx.vb
/folder2/
-auth.vb
should result:
d:/inetpub/456/folder1/test.aspx.vb
d:/inetpub/456/folder2/auth.vb
Finally
It is important to note that it should be going through all of these examples in one run. I will not be running this script for every folder, but rather the root folder 'd:/inetpub'. So there would be only one list of results that would look like this:
d:/inetpub/123/abc/folder1/regularPage.aspx.vb
d:/inetpub/123/abc/folder1/anotherPage.aspx.vb
d:/inetpub/123/abc/folder2/auth.vb
d:/inetpub/456/folder1/test.aspx.vb
d:/inetpub/456/folder2/auth.vb
I think I'd go a slightly different route than Trevor. Query for the *.compiled files, and when it finds one search that object's directory recursively for *.vb files for each *.compiled file.
GCI D:\inetpub -include *.compiled -recurse|%{GCI "$($_.directory)\.." -include *.vb -recurse|Select FullName}
If that gets you duplicate files (this would happen if you have multiple .compiled files in one folder) you can toss |Select -Unique on the end of that to resolve that issue. It would slow it down though, so I wouldn't do that unless needed.
I tried to edit the script to only include .compiled files located in folders named 'bin' but it failed. Sorry. I did add |Select FullName in there to give a listing more like what you had asked for instead of filesystem objects. Now it just lists full path and filename like you wanted.
I think this should work for you:
$Compiled = Get-ChildItem -Path d:\inetpub\*\x\bin -Include *.compiled -Recurse;
if ($Compiled) {
Get-ChildItem -Path d:\inetpub\*\x -Include *.vb -Recurse;
}

RAR a folder without persisting the full path

1) I have a folder called CCBuilds containing couple of files in this path: E:\Testing\Builds\CCBuilds.
2) I have written C# code (Process.Start) to Rar this folder and save it in E:\Testing\Builds\CCBuilds.rar using the following command
"C:\program files\winrar\rar.exe a E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds"
3) The problem is that, though the rar file gets created properly, when I unrar the file to CCBuilds2 folder (both through code using rar.exe x command or using Extract in context menu), the unrared folder contains the full path, ie. extracting E:\Testing\Builds\CCBuilds.rar ->
E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\<<my files>>
Whereas I want it to be something like this: E:\Testing\Builds\CCBuilds2\CCBuilds\<<my files>>
How can I avoid this full path persistence while adding to rar / extracting back from it. Any help is appreciated.
Use the -ep1 switch.
More info:
-ep = Files are added to an archive without including the path information. Could result in multiple files existing in the archive
with same name.
-ep1 = Do not store the path entered at the command line in archive. Exclude base folder from names.
-ep2 = Expand paths to full. Store full file paths (except drive letter and leading backslash) when archiving.
(source: http://www.qa.downappz.com/questions/winrar-command-line-to-add-files-with-relative-path-only.html)
Just in case this helps: I am currently working on an MS Access Database project (customer relations management for a small company), and one of the tasks there is to zip docx-files to be sent to customers, with a certain password encryption used.
In the VBA procedure that triggers the zip-packaging of the docx-files, I call WinRAR as follows:
c:\Programme\WinRAR\winrar.exe a -afzip -ep -pThisIsThePassword "OutputFullName" "InputFullName"
-afzip says: "Create a zip file (as opposed to a rar file)
-ep says: Do not include the paths of the source file, i.e. put the file directly into the zip folder
A full list of such switches is available in the WinRAR Help, section "Command line".
x extracts it as E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\, because you're using full path when declaring the source. Either use -ep1 or set the default working dir to E:\Testing\Builds.
Use of -ep1 is needed but it's a bit tricky.
If you use:
Winrar.exe a output.rar inputpath
Winrar.exe a E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds
it will include the input path declared:
E:\Testing\Builds\CCBuilds -> E:\Testing\Builds\CCBuilds.rar:
Testing\Builds\CCBuilds\file1
Testing\Builds\CCBuilds\file2
Testing\Builds\CCBuilds\folder1\file3
...
which will end up unpacked as you've mentioned:
E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\
There are two ways of using -ep1.
If you want the simple path:
E:\Testing\Builds\CCBuilds\
to be extracted as:
E:\Testing\Builds\CCBuilds2\CCBuilds\file1
E:\Testing\Builds\CCBuilds2\CCBuilds\file2
E:\Testing\Builds\CCBuilds2\CCBuilds\path1\file3
...
use
Winrar.exe a -ep1 E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds
the files inside the archive will look like:
CCBuilds\file1
CCBuilds\file2
CCBuilds\folder1\file3
...
or you could use ep1 to just add the files and folder structure sans the base folder with the help of recursion and defining the base path as the inner path of the structure:
Winrar.exe a -ep1 -r E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds\*
The files:
E:\Testing\Builds\CCBuilds\file1
E:\Testing\Builds\CCBuilds\file2
E:\Testing\Builds\CCBuilds\folder1\file3
...
inside the archive will look like:
file1
file2
folder1\file3
...
when extracted will look like:
E:\Testing\Builds\CCBuilds2\file1
E:\Testing\Builds\CCBuilds2\file2
E:\Testing\Builds\CCBuilds2\folder1\file3
...
Anyway, these are two ways -ep1 can be used to exclude base path with or without the folder containing the files (the base folder / or base path).