Check for new file and convert to dds [closed] - powershell

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a folder in which jpgs are created. When a new JPG is created, I need to resize it (to 2048x2048 pixels for instance) and convert it to a .dds (dxt1). All of this automatically.
I started to Google batch file commands, then understood that it would probably be better to use powershell and found out about ImageMagick converter. But I'm not sure of any of this and don't know where to begin...

I am no expert on Windows BATCH, but you can do something along these lines. Save the following code as JPG2DDS.BAT and run it using
JPG2DDS
or by double-clicking it.
#ECHO OFF
REM Start of infinite loop monitoring directory for JPGs
:TOP
echo Checking for files...
REM Work through all JPEG files converting to DDS
FOR /F %%f IN ( 'DIR /B *.JPG' ) DO (
ECHO Processing file %%f...
convert "%%f" -resize 2048x2048 "%%f.dds"
REM If it worked, rename the original file so we don't do it again
REM If it didn't work, we'll try again next time round
IF %ERRORLEVEL% == 0 (
ECHO Conversion successful
REN "%%f" "%%f.converted"
)
)
REM Sleep so as not to overload Windows
ECHO Sleeping...
SLEEP 10
GOTO TOP
All the commands above are described with examples here.
The convert command is part of ImageMagick which you will need to install. Before you run this script, make sure that you can convert a single JPEG to DDS using a command like this:
convert someImage.jpg -resize 2048x2048 result.dds

Related

Calling a random folder in a Batch script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
Improve this question
I have a simple script which closes an open window of "wallpaper engine" using its own arguments and then another line calls for the next wallpaper inside a folder:
1803613842
How can i pick the next wallpaper from a random folder instead of calling a specific one?
#echo
"C:\Program Files (x86)\Steam\steamapps\common\wallpaper_engine\wallpaper64.exe" -control closeWallpaper "Wallpaper #$"
"C:\Program Files (x86)\Steam\steamapps\common\wallpaper_engine\wallpaper64.exe" -control openWallpaper -file "C:\Program Files (x86)\Steam\steamapps\workshop\content\431960\1803613842\project.json" -playInWindow "Wallpaper #2" -width 1920 -height 1080
exit
The first step is to make a bash array of all the folder names which are available.
Once you have an array (here caled #dirs), you can pick a random item as follows:
randomdir=${dirs[$RANDOM % ${#dirs[#]} ]}
This generates a random number between 0 and the length of the array, and then returns the element at that index.
If you can get a comma-separated or similar list of directories, you can create the dirs array by doing:
my_dirs="abc,def,ghi"
IFS=',' read -ra dirs <<< "$my_dirs"
randomdir=${dirs[$RANDOM % ${#dirs[#]} ]}

What does "cd.." mean in powershell? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I already know what it does: It simply goes one directory or folder backwards.
But what's mysterious for me are those two dot.
cd.. #it has the same function as popd with the difference that it changes the
#current working directory
If someone tell me what is the philosophy of putting those two Dots, i would really appreciate it.
.. in filesystem paths represents a given path's parent path.
Without an explicit path preceding the .., the implied path is the current [working] directory, so the .. therefore refers to the current directory's parent directory.
In short: cd with an argument of .. changes to the current directory's parent directory, i.e., the directory one level above in the directory hierarchy.
Shell-specific use of .. with cd:
The legacy command processor, cmd.exe ("Command Prompt") - seemingly with the internal cd command specifically (see Mofi's comments on the question) - considers an . character to implicitly start the cd command's argument.
Therefore, separating the cd command from the .. argument with a space character, as usual, isn't necessary; that is, instead of cd .. you can type cd.., which is a shortcut that users of cmd.exe have grown accustomed to over the years.
PowerShell allows . characters to be used in command names, so submitting cd.. does not invoke the cd command (a built-in alias for the Set-Location cmdlet) with argument .. - instead, it looks for a command literally named cd..
To accommodate cmd.exe users who are accustomed to the cd.. shortcut, PowerShell comes with a parameter-less function literally named cd.., so that submitting cd.. as a command in PowerShell effectively works the same as in cmd.exe.
However, note that only cd.. works, not also specifying additional components; that is, something like cd..\Foo (which works in cmd.exe) fails.
Get-Command cd.. | Format-List shows information about this function, which reveals that it simply calls Set-Location .., which is PowerShell's equivalent of cmd.exe's cd ..
These two dots mean "One upper level in the directory".
cd specifies to change the directory and .. means "upper level". So, cd.. means exactly what you stated in your question.
Example: let's say you are in the folder C:\x\y. If you type cd.., you'll be on C:\x

Batch script to move zip files based on year modified

I realize there are a lot of questions already answered about doing something similar. I have researched what I am trying to do and didn't find anything that seemed to apply to what I am trying to do. There are a few factors combined in what I am trying to do and I don't know a lot about batch scripting.
First, I need to look at zip files with a certain naming scheme only. The way these are named is file1234.zip, file2345.zip, file3456.zip, etc... This naming scheme is automatically generated and already in place. The number in the name has nothing to do with the date it was modified or created. There are other zip files in the source directory I would want to ignore. This can be solved with wildcards. "file*.zip"
Next, I need to move only certain files fitting the above criteria, that were modified within a specific year. i.e. move zip files modified in 2000 but leave all other files alone. The year the files were modified would be a constant and would be designated in the script.
When combined, if file2345.zip was modified in 2000 and the other files were last modified in other years, then file2345.zip would be moved and all others would be ignored.
What I have learned:
Wildcards are valid characters in the middle of a file name.
To get the dates modified for all files matching my naming criteria
forfiles /M file*.zip /C "cmd /c echo #file #fdate"
With the above, how do I look at just the four-digit year?
I have no objections to using xcopy or robocopy for the actual file move.
Any suggestions or ideas would be greatly appreciated.
Assuming this command dir file*.zip |find /i "file" shows something like this:
18/08/2015 11:58 45,617 file2456.zip
18/08/2015 11:58 156,789 file36789.zip
then this code should work:
#echo off
md "d:\new folder" 2>nul
for /f "tokens=3,*" %%a in ('dir file*.zip ^|find /i "file" ^|find "/2000 "') do move "%%b" "d:\new folder"

Execute Tokens in C: What does '.' and '/' mean in './'? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When executing a C-program, we have to type a '.' token and a '/' token together followed by our program name:
./program
What do each of the these tokens mean? Why do they need to be together to work?
The ./ syntax just refer to the current directory (Actually . is the current directory while / is the path separator). This is needed because the shell will look into folders specified in $PATH environment variable for executables. Since the program is in the current directory which is not inside PATH by default you need to specify the folder you are running it from.
Actually, this has nothing to do with C. This value is simply passed along to the operating system and used to locate a file.
But on Windows, it doesn't appear to have much meaning at all. . is the current directory and the / is simply the path separator between the current directory and program. Since the OS defaults to the current directory, it refers to the same path as just program.
. means current path
.. means parent.
/ means root or path separator. Depends on Unix/Windows/Mac
./ means current path and relates, towards RHS.
./Program means PWD and Program as Directory or Location.

Finding long file names? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have some zipped plug-ins, when I try to unpack that the unpacking fails. When I looked deep into it I found that the some of the files are exceeding 256 characters, which I guess is not allowed in WINDOWS operating system.
So my question is there any way to find out if any file name inside a particular folder exceeds 256 characters?
I'm using WINDOWS XP operating system.
Thanks in advance!!
Anand
Without having your zip file is a bit harder to find out if the problem is exactly what you said... AFAI remember, 7zip would truncate the long file names, not "not extract" them. But I don't have any zip with long names to test.
I'd try some things:
Open the zip file with 7zip and try to rename the long names, instead of extracting them.
Try to open the zip file with other zip app, like (izarc)[http://www.izarc.org/news.html], and rename the files
If you don't have access to another computer, try to use one of the available online unzippers. For example: http://jcarleemae.wen.ru/extract.html