1.

Solve : check for data in a folder using a batch file?

Answer»

How can I check for data in a folder using a batch if statement. So basically if folder A has data or directories in it, then do these set of commands, one gotcha here is that I don't know what the name of the data or folders will be???Not being specific about your OS, nor being specific about subfolders of folders, I can only give you a pseudo code outline of how you might go about this:

Code: [Select]@echo off
for /f %%i in ('dir /a:d /b drive:\dirname') do (
do your thing for directories
)
for /f %%i in ('dir /a:-d /b drive:\dirname') do (
do your thing for files
)

Good luck. 8-)
Hah, I am ALSO looking for a solution to the same problem. I almost submitted the following to a tech service email:


I would like to know how to perform operations on all files within a drive or folder (I.e, within that drive or folder, and any subfolders they CONTAIN).

For example, say I have a folder called "Websites". Within this folder are two subfolders "Images" and "HTML". I want to make a batch file that will reside in the "websites" folder that will rename all extensions in the "html" subdirectory to .htm, and all the images in the "images" directory to .tiff.

This would be applied on a large scale so switching from one directory to the other by typing in CD directory to the batch file would be impossible. Instead I want the batch file to locate, enter and perform operations within all subdirectories by itself.

I hope this is not too confusing. I am looking forward to your reply.


Sidewinder, I READ your reply but unfortunately I am not familiar enough with batch file programming to apply your psuedocode to that language.

I appreciate that your psuedocode should be sufficient for the average person, but if you have the time could you help me out and write the code for the above operation for a windows XP cmd batch file? I would very much appreciate that.

Either way, Thanks for your time.Quote

For example, say I have a folder called "Websites". Within this folder are two subfolders "Images" and "html". I want to make a batch file that will reside in the "websites" folder that will rename all extensions in the "html" subdirectory to .htm, and all the images in the "images" directory to .tiff.

This part is easy:

Code: [Select]ren .\images\*.* *.tiff
ren .\html\*.* *.htm

This is the part where I got completely CONFUSED:

Quote
This would be applied on a large scale so switching from one directory to the other by typing in CD directory to the batch file would be impossible. Instead I want the batch file to locate, enter and perform operations within all subdirectories by itself.

At some point in time, you will need a pointer to the files to be renamed.

With WinXP you should use a script. Batch is vastly underpowered for this type of operation. Judging from your post you would need to walk the directory tree and identify HTML and Images directories before doing any rename operation.

Good luck. 8-)



Discussion

No Comment Found