Writing and integrating a batch file to create directory listing - windows

I'm trying to modify the Windows 7 "Print Directory Listing" option to allow me to create a simple text list of the files located in the folder, saved to that folder. A couple of hours of Googling only found "Print Directory Listing" directions.
I've tried a few attempts at modifying the PRINTDIR.BAT file, but I'm pretty sure my output directory selection is wrong.
Here's my current effort, pared down to the bare metal.
#echo off
dir %1 > ".\_Listing.txt"
exit
The batch file is saved into the C:\Windows\ folder, and I suspect it's attempting to create the file in and of that folder, instead of the desired target folder.

Related

Moving files of a particular File Extension from multiple folders into one specific folder

I'm only started scripting a few weeks ago and have been testing a few scripts I've put together with help from some posted on this site.
Currently I'm struggling and require some help or assistance.
I want to be able to move all files with any particular/given file extension, from within any directory, and any of their sub-directories, if they exist. I just want the files, not the folders copied.
The script works, I'm hoping for anyway, as such:
You enter the directory you want to move the files from e.g. D:\TestMove
You enter the directory you want to move the files to e.g. D:\Test
You enter the file extension of all of the files that you want to be moved from the given directory, and then sub-directories eg. .txt
If the directory you're moving them to doesn't exist, it should be created.
So in my case, I've got the directory D:\Test, with multiple sub-directories, (TestMove\Test2, etc.), and within each of those directories multiple .txt files, (for example). I want to be able to move all of the .txt files from the D:\Test directory to wherever I want.
At the moment, it's just moving the files from the directory I choose, but not from within the sub-directories.
I'm happy to get this script ripped to bits so that I can learn where I'm going wrong.
set /P DMF=Please enter Directory moving from:
set /P DMT=Please enter Directory moving too:
set /P FEX=Please enter File Extension:
if not exist %DMT% mkdir %DMT%
for %%a in (%FEX%) do (
echo Moving all %%a files to "%DMT%" ...
move "%DMF%\*%%a" "%DMT%"
)

CMD move files without knowing folder name

I'm using Windows CMD via an ANT Build file to move files from a sub-folder into a parent folder that is three levels up. The structure looks like this:
containingFolder
-tempFolder
-unkownNamedFolder
-contents.xyz
Using linux I can do this with the command mv */*.* .. with the current working directory being the temp folder. I don't know what the unknownNamedFolder will be called, but I do know that it will always be the only folder within the temp folder and that whatever content is within it needs to be extracted out to the containingFolder so that temp can be deleted and only the files will remain.
I've tried a command such as /c move *\*.* .. 2>NUL but this doesn't work.

Drag N' Drop 100+ Files Batch

I've been searching for an answer on the internet and can't seem to get a definitive one. I've been having an issue with getting a .bat file to accept more than 80 files at once for conversion and file look up with a batch script that links to a python script.
Here is an example of what I'm doing, it's easy enough...
#ECHO OFF
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" %*
PAUSE
Again, this seems to work with 80 files drag and dropped unto the batch script but doesn't seem to work with more than that. Is there something I'm doing wrong?
they are located in their own directory. I would prefer to drag the
entire set of files, or the entire directory, into my batch file and
iterate over the files
that's possible:
drag the folder to your batch file and use
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" "%~1\*"
As an alternative you could drag any one of the files to the batch file and use %~dp1 to get the folder and
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" "%~dp1\*"
to process all files in this directory.

Copying files from cab to folder

I'm trying to copy the files from .cab file to a normal folder. I don't have extract.exe on my Windows 7. And using xcopy /s .\file.cab .\extracts throws an error saying "Cannot perform a cyclic copy". I've googled the error, but found nothing applicable. The destination folder is empty, and otherwise it can only copy the .cab file but not the files within it. I want to copy all the files within .cab file into a folder. Can someone help? I want this to work on a client environment so I don't want to download any other tools, just command line if I can.
Try any of the following commands. Both should be included in your windows 7
expand file.cab .\extracts
extrac32 file.cab /L .\extracts

iexpress hard-coded extraction destination folder?

I'm using iexpress to make a self extracting executable. Is there a way I can hard-code an extraction destination folder (preferably into a temp folder somehwere) so as to not have the extraction pop up the "Please type the location where you want to place the extraced file." dialog?
There's no direct way to do this. (You can see my other answer for a longer explanation about it.)
The easiest solution is to make an IExpress archive that runs an "installation program", which is really just a batch file that copies the extracted files where they're needed.
In IExpress, you'd launch the batch file like: cmd /c persist.bat. And persist.bat looks something like:
#echo off
xcopy /y * "%temp%\persistent\"
del /f "%temp%\persistent\persist.bat"
(The last line is a nicety to hide the fact that you used this batch file to copy the extracted archive.)
Yes, this is possible through the use of an .INF file when you select "Extract files and run an installation command". You must set the .INF file as your Install Program and under the DestinationDirs section you would put the path to the directory you want the files to go to. Here is an example of an .INF file:
[version]
signature="$CHICAGO$"
[DefaultInstall]
CopyFiles=install.files
[DestinationDirs]
install.files=-1,"C:\Program Files\MyCustomDir"
[install.files]
MyFile1.txt
MyFile2.bmp
So this sample shows that the installer will install to C:\Program Files\MyCustomDir. The files under the install.files should list all the files you want to copy to that folder. They must be included in your installer when you are selecting the files to add.

Resources